Last week i had my first 👊✨💪 rounds with the Mutiny library because i needed a Reactive REST endpoint in my Quarkus project. This was not as obvious as it sounds so i thought i’ll share my new fresh insights about the Mutiny library in Quarkus;
Quarkus documentation specifies the Mutiny library as the preferred library for Reactive use-cases;
what stood out is that most Mutiny examples are using a new String as an example. So, my question remained;
how do i connect MyRequestService with Mutiny in Quarkus
This would be something as:
Uni<MyRequestService> lMyRequestServiceUni = Uni.createFrom().item( ... ) ...
MyRequestService already uses a callback structure, so I tried a callback method towards Mutiny.
So MyRequestService, or an underlying callback object, needs to implement an UniEmitter Consumer. But first, to become Reactive, my old blocking REST endpoint needs to return Uni<MyJsonResult> instead of MyJsonResult;
The ServiceResource just forwards the call to the Service.
MyRequestService creates a MyJsonResultConsumer and delivers this to the Mutiny Emitter. The resulting Uni<MyJsonResult> is returned to the ServiceResource.
Finally MyJsonResultConsumer is here the actual callback object; method ready() calls complete() on the UniEmitter concluding the callback towards Mutiny.
Remember that Mutiny needs to provide the UniEmitter with a call(back) to accept(), so you should check for null pointers (or use a Semaphore oid). 👮🏻♂️
Have fun with the Mutiny library in Quarkus and feel free to question, update and/or improve (i already spotted a 🐝 in the code) 🤓