Reputation: 393
Have written a microservice(Using webFlux) which in turn calls three other microservices(Not using webflux). New microservice call the other three using flatmap. and controller is returning Mono . Is this correct Design. Do I need to pushlishOn?
Mono<String> result =service1.api(input)
.flatmap(innput-> service2.api).flatmap(input-> service3.api);
And Controller is also Returning Mono . Is the design correct. Will it be working in non-blocking way?
Upvotes: 0
Views: 59
Reputation: 44745
The publishOn
method does not change code either into non-blocking or blocking code. All it does is force downstream operators to run in a different thread. However, if the service calls made within those threads are blocking, then you'll just be blocking another thread if you use publishOn
.
So, to answer "Will it be working in non-blocking way", it actually depends on how you implemented service1.api()
, service2.api()
and service3.api()
. If they synchronously fetch your data, then it will still be blocking, no matter what you do.
However, if you use the new WebClient
API for example to reactively fetch your data from your three microservices properly, then yes, it should be non-blocking.
Upvotes: 1