quarkusreactivecompletable-futuremutinycompletion-stage

Dispatch a CompletionStage / CompletableFuture API service in a Reactive REST GET endpoint with Quarkus/Mutiny


After implementing a Reactive REST GET endpoint with Quarkus / Mutiny using a callback structure and checking the variant with a blocking service i finally played with a CompletionStage / CompletableFuture API version;

How do i call a CompletionStage / CompletableFuture API service from my Reactive REST GET endpoint with Quarkus/Mutiny


Solution

  • Again it turned out to be quite simple (although the underlying idea may be more complex);

    enter image description here

    The ServiceResource just forwards the call to the Service.

    enter image description here

    MyRequestService creates a MyJsonResultCompletableFuture (CompletableFuture implements CompletionStage) and delivers this to the Mutiny Uni with method completionStage(). Another possibility would be using;

    Uni.subscribe().asCompletionStage()

    The resulting Uni is returned to the ServiceResource.

    enter image description here

    Finally MyJsonResultCompletableFuture blocks the call from MyReactiveServiceResource / MyRequestService waiting for a completionStage. Method ready() accomplish this stage and returns the MyJsonResult to Mutiny (acting like some kind of callback).