Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot 2. Async API. CompletableFuture vs. Reactive

My application is heavily relying on asynchronous web-services. It is built with spring boot 1.5.x, which allows me to utilize standard Java 8 CompletableFuture<T> in order to produce deferred async responses. For more info see https://nickebbitt.github.io/blog/2017/03/22/async-web-service-using-completable-future

Spring boot 2.0.x now comes with the starter pack that can utilize reactive paradigm. Spring WebFlux is the framework, which is implementing reactive HTTP.

Since I have my API implemented as described in the first paragraph, will I gain much by redoing my services to use non-blocking reactive approach? In a nutshell, I'll have non-blocking API as well, right?

Is there an example how to convert async API that is based on CompletableFuture<T> to Mono<T>\Flux<T>?

I was thinking to get rid of servlet-based server altogether (Jetty in my case) and go with Netty + Reactor.

Needless to say that I am new to the whole reactive paradigm.

I would like to hear your opinions.

like image 638
Ihor M. Avatar asked Aug 01 '18 19:08

Ihor M.


1 Answers

I have two things to say:

Q: Is there an example how to convert async API that is based on CompletableFuture to Mono\Flux?

A: 1) You have to configure endpoint in a bit different way https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html

2) CompletableFuture to Mono\Flux example: Mono.fromFuture(...)

like image 53
shpitc Avatar answered Oct 13 '22 00:10

shpitc