-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Quarkus startup fails, if jaxrs filter injects a mp reactive messaging emitter #10159
Comments
What's the use case for using an Emitter inside a Filter? It's not a use case we've planned for |
Hi Ken, The quarkus will not start if an emitter is injected anywhere in a class injected into a Jaxrs filter or a dependency thereon. For example, following will fail: @Provider public class MyContainerRequestFilter implements ContainerRequestFilter { @Inject ControllerA controllerA; } @Dependent public class ControllerA { @Inject ControllerB controllerB; } @Dependent public class ControllerB { @Inject @Channel("mytopic") Emitter emitter; } |
I'm not 100% certain, but the issue might be that JAX-RS providers by default are not CDI Beans? |
Right, so the provider isn't a JAX-RS Resource so injection won't work |
So, CDI injection in JAX-RS providers are not supported in Quarkus? |
@mkouba can confirm, but I don't think so. |
I think that JAX-RS providers do support injection. If you look at the stack trace it seems that ArC fails to create a bean instance of
We need to find out why there are no emmiters registered... |
So I think that the problem is that JAX-RS filters are instantiated before A workaround could be to change the scope of Another workaround would be use @MessageHeader
@Provider
public class RequestFilter implements ContainerRequestFilter {
private static final String X_MSG = "x-message";
@Inject
Instance<MessageSender> instance;
volatile MessageSender controller;
@Override
public void filter(ContainerRequestContext crc) throws IOException {
if (controller == null) { // not atomic but good enough, we'll create few more instance at worst ;-)
controller = instance.get();
}
String msg = crc.getHeaderString(X_MSG);
if (msg != null) {
controller.send(msg);
}
}
UPDATE: if using the quarkus master branch you can replace the snippet above with: @MessageHeader
@Provider
public class RequestFilter implements ContainerRequestFilter {
private static final String X_MSG = "x-message";
@WithCaching
@Inject
Instance<MessageSender> instance;
@Override
public void filter(ContainerRequestContext crc) throws IOException {
String msg = crc.getHeaderString(X_MSG);
if (msg != null) {
instance.get().send(msg);
}
}
|
So can we close this one as a proper workaround exists? Maybe we need to add some sort of documentation? |
I am going to close this because for RESTEasy Classic the workaround Martin mentions above works and for RESTEasy Reactive there is no such limitation as the JAX-RS Filter lifecycle is completely controlled by CDI |
Describe the bug
If Quarkus uses MicroProfile Reactive Messaging with incoming and outgoing topics and a JAXRS
javax.ws.rs.container.ContainerRequestFilter
injects (indirectly) anorg.eclipse.microprofile.reactive.messaging.Emitter
, than startup fails withjava.lang.ExceptionInInitializerError
caused by 'Unable to find a emitter with the name <topicname>, available emitters are: []'.Expected behavior
Successful quarkus startup.
Actual behavior
Exception in thread "main" java.lang.ExceptionInInitializerError
To Reproduce
Steps to reproduce the behavior:
mvn clean package
java -jar target/emitter-jaxrsfilter-1.0-SNAPSHOT-runner.jar
Configuration
Screenshots
Environment (please complete the following information):
uname -a
orver
: Linux 5.4.0-37-generic Arc - implement CDI inheritance rules properly #41-Ubuntu SMP Wed Jun 3 18:57:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linuxjava -version
: openjdk version "11.0.7" 2020-04-14OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)
mvnw --version
orgradlew --version
): Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)Additional context
@Incoming
annotation, quarkus starts without error.The text was updated successfully, but these errors were encountered: