-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How could I use Quarkus in CDK applications ? #1273
Comments
What worked at this point is the programmatic configuration via |
Anyone there could help please ? |
I don't think you need to mix Quarkus with CDK. However, if you want to, I believe your question is specific to Quarkus. Could you open an issue or a discussion at https://github.com/quarkusio/quarkus/? What I would do is use SmallRye Config as a standalone library. See the example for configuring mapping and default values: https://github.com/smallrye/smallrye-config/tree/main/examples/mapping. |
BTW, maybe if you write a Quarkus command line application, you could inject properties and create the stack and app from there. https://quarkus.io/guides/command-mode-reference |
@scrocquesel : "I don't think you need to mix Quarkus and CDK". While I don't mandatory need to do that, it's extremely important to be able to do that. Unless you're saying that CDK isn't supported by Quarkus, in which case please mention it clearly. Generally speaking, nobody "needs" to use Quarkus, or Spring, or Micronaut, or Helidon, etc., but being able to use them is much better than the opposite :-). And I have to say that it is quite uncommon for a Quarkus project to advise not trying to use Quarkus, but to use instead SmallRye libraries in a stand-alone manner. As you probably know, using Quarkus with CDK is a very valuable software architecture which gives access to one of the most powerful IaC platform (CDK) and, in the same time, to the one of the most powerful micro-services platform (Quarkus). I really don't see what might be the added value of avoid using Quarkus. Additionally, using SmallRye as a standalone library won't be of any help because the issue will persist as long as the CDK app is directly and explicitly instantiated and, hence, whatever you do, Quarkus or anything else couldn't handle this instantiation performed outside it. My point was to look for a solution such that to start the CDK app as a Quarkus app, by modifying perhaps the command in the
and here is the config of the
So, as you see, the CDK app is started as a simple JAR, not at a Quarkus one and, hence, not being a Quarkus app, it can't take advantge of Quarkus feature, like MP Config, etc. I think that one possibility would be to modify the You should probably imagine that, before opening an issue here, I did it at the Quarkusio site and, if I finally landed here, this is because the guys there asked me to do it here. Now, if you send me back to them, then the circle is closed :-). Thank you very much for providing me with this link to the documentation but it isn't relevant, for the same reason mention above. |
Thank you for the very detailled explanation. This issue is not related to this extension. What your are looking for is how to run a quarkus application from command line. After having created a quarkus command line application with the tutorial, move your cdk classes to the app, add the required package dependencies, and copy the cdk.json file to the quarkus project. Edit the cdk.json and change the app config value: then, you can run
|
@scrocquesel : Many thanks for your help. "then, you can run cdk ls ..." Not sure how do you run that as the Quarkus app is executing in foreground and, hence, you can't run any command. And trying to run it in another terminal raises this exception:
Another issue is that running |
You don't need to start the quarkus app first. Cdk is basically a wrapper that set up env variables and start the app command. |
@scrocquesel : I'm running the following command:
This looks in the
The Quarkus app starts, here is the entrypoint:
I'm getting that:
That's all. I tried to have
in the |
waitfor exit is only needed if you run a background thread. Let the app return after tu the app.synth |
As I said, I need to call
} displays:
|
This is the dev mode experience with The With what I told you to do:
import com.myorg.MyProjectApp;
import io.quarkus.runtime.Quarkus;
import io.quarkus.runtime.annotations.QuarkusMain;
@QuarkusMain
public class JavaMain {
public static void main(String... args) {
Quarkus.run(MyProjectApp.class, args);
}
} package com.myorg;
import software.amazon.awscdk.App;
import software.amazon.awscdk.Environment;
import software.amazon.awscdk.StackProps;
import java.util.Arrays;
import io.quarkus.runtime.QuarkusApplication;
public class MyProjectApp implements QuarkusApplication {
public void main(final String[] args) {
App app = new App();
new MyProjectStack(app, "MyProjectStack", StackProps.builder()
.build());
app.synth();
}
@Override
public int run(String... args) throws Exception {
main(args);
return 0;
}
} |
It looks like it, as a matter of fact, but I don't know why is that as I didn't run
Well, I don't think that reading the code would be the right way here. In order to avoid any possible confusion, please use this reproducer here (https://github.com/nicolasduminil/quarkus-s3). The name isn't well chosen but it illustrates my point. Run it as follows:
You'll see what I mean. Please feel free to modify it in order to make it work. Please notice also that you can't use statements like this one:
if you want to use CDI further. Many thanks in advance. Nicolas |
@scrocquesel : Any comment ? |
I'll try to have a look soon. |
I'll create a pr on your repo. You defintely need to read more about the framework you use. I changed the scope of some bean to Singleton to avoid the proxy bean to call the base constructor more than once and also for the stack to properly call the ctor when injected. If it were a proxy (with Hope this will help you move forward. |
Great, looking forward for it. When do you think you'll be doing that ?
In my opinion, the role of a contributor isn't to comment on the issuer lack of knowledge, but to help to fix the issue. Which you're doing, of course, but you really don't need this kind of comments. |
My bad, I've seen you've already created the PR, sorry for not having realized that. Kind regards, |
@scrocquesel : Hi, I'm so sorry but I have to reopen once again this issue because something isn't right here, as far as CDI is concerned. I modified the master branch of the project to add some MP Config in the More precisely, the following sequence:
displays:
I'm not sure why is that and, for having used a lot MP Config, I didn't see this issue yet. I persist to think that it must be something related to the peculiarities of the AWS CDK extensions. But I might be mistaken, in which case I'm relying on you to help me, without criticizing me for my lack of knowledge. Many thanks in advance. Kind regards, Nicolas |
The result is as expected. The ctor is executed, THEN, the properties are injected. Use ctor injection. If you don't want to have a bunch of Please, for anything not directly related to the AWS clients SDK this project supports, you should ask the Quarkus main project. A lot more people could help you with these basics. |
Got it, thanks. |
Hello,
I'm facing the following case: I have a CDK application class defining a
Stack
in which I need to use MP Config via Quarkus@ConfigProperty
annotations. For example:The class
MyStack
is the one where I need to use:Given that the class is manually instantiated by calling its constructor, it isn't handled by Quarkus and, hence, the properties aren't injected. I've tried to inject
MyStack
intoMyCdkApp
but runningcdk deploy
I gotThis app contains no stacks
, showing that, for some reasons, the injection didn't work.Is there any possibility to either instantiate
MyStack
via its constructor while being handled by Quarkus (probably not) or to inject it such that to be "seen" by the CDK ?Many thanks in advance.
Nicolas
The text was updated successfully, but these errors were encountered: