2

I am newbie to webflux concepts and trying to understand the background behind communication among three independent Reactive Apps.

Lets suppose there are three services: A, B and C, of which A and B has endpoints that returns Mono<> and C is a Reactive DB.

Consider:

A makes a reactive call to B.
B makes a reactive call to C.

Unless A subscribes, the data flow should'nt have started. This was my understanding.

when I did this in implementation, I could see , when A makes a webclient request to B as below,

//code in Microservice-A
return webClient.get().uri("B").retrieve().bodyToMono(Response.class);

Even though I didnt subscribe , I could see the onNext(data) and onComplete() events fired in logs of microservice B. So clearly my understanding was wrong.

If WebFlux framework in each service is subscribing already, that means it is blocking right. Can anyone please clarify how it works and advantage of this? TIA.

UPDATE: Here is the controller in Microservice-A. Assume this is called from a front end React app where the subscription is actually done.

Can I say, data is prefetched in Microservice - B(at webflux framework level) and it is really upto the TCP network to stream it to Microservice-A depending upon its need

@RestController
public class PandaClController {

@Autowired
WebClient webClient;

@GetMapping("get-panda")
public Mono<Response> getSpotifyData() {
    return webClient.get()
            .retrieve()
            .bodyToMono(Response.class);
}}
Dinesh Narayan
  • 105
  • 2
  • 9
  • 2
    Is difficult to tell because you did not provide enough code of service A, but does this answer your question? [who calls subscribe on Flux or Mono in reactive webapplication](https://stackoverflow.com/questions/56487429/who-calls-subscribe-on-flux-or-mono-in-reactive-webapplication). Also https://stackoverflow.com/questions/50795071/how-rest-endpoints-are-auto-subscribed-while-calling-from-browser-rest-client – tkruse May 10 '20 at 00:55
  • Thanks. This explains the case when the request is fired from postman/web browser but could not relate with server to server communication. May I know what information of service A is needed to proceed further. – Dinesh Narayan May 10 '20 at 05:51
  • In your question you need to show how the method is invoked which contains the `return` line that you pasted. Is it inside a Spring Controller `@RequestMapping` like in the linked question, or how else? What happens with the Mono inside service A after being returned from the line that you pasted? Because Spring can auto-subscribe a mono/flux that is returned from a controller. – tkruse May 10 '20 at 06:38
  • 1
    Also related: https://stackoverflow.com/questions/48181801 – tkruse May 10 '20 at 06:46
  • Some information also here, also it may not answer your question: https://stackoverflow.com/questions/52244808/. Maybe you can also describe in your question how you called your service A. – tkruse May 10 '20 at 06:55
  • Sure. I have added my rest controller of service -A. you said: "Because Spring can auto-subscribe a mono/flux that is returned from a controller" Is there any way to avoid this and send it as a mono to upstream systems and data flow is triggered only when my upstream system subscribes.? – Dinesh Narayan May 10 '20 at 07:20
  • Also from the links that you have shared, Can I say, data is prefetched in Microservice - B(at webflux framework level) and it is really upto the TCP network to stream it to Microservice-A depending upon its need? – Dinesh Narayan May 10 '20 at 07:33
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/213531/discussion-between-dinesh-narayan-and-tkruse). – Dinesh Narayan May 10 '20 at 07:42

0 Answers0