1

So far I have been implementing Async non-blocking IO with CompletionStages but I am now attempting to build a Spring-Webflux service while attempting to reuse existing code.

I have an existing HttpClient that returns a CompletionStage and as part of my logic I need to perform 3 HTTP calls, each dependent on the last. I know that I can convert a CompletionStage to a Mono using Mono.fromCompetionStage, but I am wondering how I can fluently compose the calls so that my Rest Controller can return a Mono representing all the operations in sequence.

I know that if I was just using CompletionStages I could chain them using thenCompose:

return client.firstCall()
             .thenCompose(client::secondCall)
             .thenCompose(client::thirdCall)  

Any idea what the best way to achieve this would be with using a Mono. If the answer is to take the resulting CompletionStage from the above code and do Mono.fromCompletionStage I see little point, as Spring-Weblfux supports returning CompletionStages.

Dean
  • 1,833
  • 10
  • 28

0 Answers0