0
votes

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?

1
"Will it be working in non-blocking way?", that depends on how your service1.api(), service2.api() and service3.api() methods work. Are those non-blocking or not? Feel free to share the code you used to write those. - g00glen00b

1 Answers

1
votes

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.