-
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
Subscribing to CompletionStage
returned by Event.fireAsync
doesn't seem to work correctly
#29191
Comments
Or maybe is my understanding of how Something needs to be able to subscribe to whatever the observer does...In this case should there be some custom subscriber that does something in the observer? |
Yes, CDI observer methods must always return
The returned
CDI async observers were not designed to participate in a reactive stream. The logic used inside observer method is expected to be synchronous/blocking.
You can only subscribe to the result of the notification. |
@mkouba do we perhaps need to improve the documentation? |
Well, our documentation does not cover the details of standard CDI functionalities. We could try to add something somewhere. But where is the border line, i.e. which features to mention and which not... |
My point on this is that it's mixing standard and non-standard behavior, so it's really hard for users to know what exactly to expect. I think a few examples in the documentation would go a long way |
Well, most (if not all) non-standard features are described in the docs and everything else should be standard. And this behaves as defined by the spec. It's the user creativity that mixes apples and oranges ;-). But I get your point. We could add something like "CDI in the reactive world". But it would be basically just an incomplete list of unsupported combinations. Note that Weld docs has roughly 190 pages and does not mention reactive at all ;-). |
Even though the CDI specification doesn't seem to require observer methods to declare a return type of |
Right, I see your point @mkouba. |
Yeah, that's a good idea - making things explicit for users is usually very helpful |
Yes, that would make sense. The truth is that the CDI spec implicitly mandates to ignore the return type but it would not hurt to fail the build. NOTE: Unless there's someone who is using an observer method in a very creative way, i.e. call an observer method directly... which is not forbidden either. |
Lots of good info on this thread. Thank you all for your comments. After I created it I kinda felt like the issue was mine in that I wasn't understanding how it should work. Based on all these great comments my understanding is that observer methods shouldn't be used with reactive and that we should find a different solution for what we're trying to do? Maybe use the Vert.x In my case the thing firing the event doesn't necessarily have to care about the result of what the observer does, but the observer does do reactive "stuff" (using Hibernate reactive) and therefore something needs to subscribe to it's result. So maybe I need to create a custom subscriber or something. The example I attached to this thread was a very simplified and dumbed-down example. |
This is key info! The The
This is also key info and would be great if it were documented somewhere. Maybe it is and I was just lazy and didn't go looking for it :) |
@ingmarfjolla lots of good info here... |
Yes, you can try the
That could be difficult. It's part of the CDI API that is not released very often...
I don't think it's documented in quarkus. And the reason is that CDI itself is very mature (2009 ;-) and was not designed with reactive in mind. As I said above - we should probably mention it somewhere... :-) |
The use case actually comes from the Debezium outbox extension. @ingmarfjolla has been working on trying to contribute a "reactive" version. The way the current blocking implementation works is the consumer creates the Outbox event, and using the Then the Debezium event dispatcher observes that event and persists it into the outbox table (https://github.com/debezium/debezium/blob/main/debezium-quarkus-outbox/runtime/src/main/java/io/debezium/outbox/quarkus/internal/EventDispatcher.java#L25, https://github.com/debezium/debezium/blob/main/debezium-quarkus-outbox/runtime/src/main/java/io/debezium/outbox/quarkus/internal/DefaultEventDispatcher.java, and https://github.com/debezium/debezium/blob/main/debezium-quarkus-outbox/runtime/src/main/java/io/debezium/outbox/quarkus/internal/DebeziumTracerEventDispatcher.java). @ingmarfjolla was trying to create a reactive version of this but was trying to use the same pattern, but the problem now is the Maybe we need to get the debezium team roped into this conversation? |
So it's going to use hibernate-reactive, right? CC @DavideD
Plus our reactive team... CC @cescoffier @jponge |
Yes, using @ingmarfjolla has a prototype he's been working on (that I've been helping him with): https://github.com/ingmarfjolla/debeziumreactive/tree/quarkus-outbox-reactive-refactor/debezium-quarkus-outbox-reactive |
we are going to try the https://quarkus.io/guides/vertx-reference#eventbus . Appreciate all the info dropped here I'm learning a lot |
maybe a silly question, but is there a way when using the event bus to create codecs in the deployment module of an extension and then use them in an application? i saw this but I wasn't sure how to make use of it |
Why do you need a codec? Quarkus generates one for you automatically. If you need one just add a codec class in your app, and it will pick it for you. If you are in an extension, just produce the build item you found. |
For some reason when Quarkus starts I was getting an error that the codec would be generated, and then that quarkus failed to start because it couldn't find the class. here The logs would say `could not find class exportedevent but when I dropped the question mark I end up getting an error in my integration tests because here now since it's saying no codec was created for MyOutboxEvent. So i'm guessing I will have to produce the build item? |
For the record - here is the spec issue about validating the return type of an observer method. |
It seems that there is no consensus yet. So I suggest to log a warning for now. WDYM? |
From the issue discussion and from CDI meetings my understanding was that the main reason for why we cannot enforce A one-time warning works too but I'd say if we think its not a good way, we should just throw an error. |
My point is that we might want to be spec-compliant in the future (i.e. pass the TCK). And this could result in a TCK-fallback config property... which might be required anyway but it's still not a good thing to do. |
I don't really have an opinion, frankly. We could maybe treat this as a feature request? We do similar things elsewhere, and it would make sense. |
Do we plan on doing anything on this one? |
The spec issue was closed so the validation of the return type is probably not going to be enforced. So we could probably support observer methods that return |
Describe the bug
When trying to use
javax.enterprise.event.Event.fireAsync
, it does not seem to subscribe to theCompletionStage
that is returned.Expected behavior
If I wrap
Event.fireAsync
inside aUni.createFrom().completionStage()
, I would expect the result of the handler of the event to be subscribed to.Actual behavior
It does not
How to Reproduce?
Reproducer:
fireAsyncBug.zip
EventResourceTests.eventReverses
test failsIn
EventResource
there is a single jax-rs method:The
EventListener
class handles the event:The
Uni
returned byEventListener.onEvent
is never subscribed to. This leads me to the question "What actually is theCompletionStage
returned byEvent.fireAsync
? What does it represent?Output of
uname -a
orver
Output of
java -version
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.14.0.Final
Build tool (ie. output of
mvnw --version
orgradlew --version
)Additional information
No response
The text was updated successfully, but these errors were encountered: