who calls subscribe on Flux or Mono in reactive webapplication
Mono
and Flux
concepts exist only within your application, while HTTP protocol is used to communicate between your postman/chrome app and your application.
Internal classes of the Spring Webflux framework subscribe to Mono
and Flux
instances returned by your controller methods and map them to HTTP packets based on the MediaType
that you specified in RequestMapping
.
It depends on which server you use.
For instance, Tomcat, Jetty (Servlet 3.1 non-blocking I/O) - ServletHttpHandlerAdapter
from org.springframework.http.server.reactive
package.
Subscription happens in service method:
@Override
public void service(ServletRequest request, ServletResponse response) throws
ServletException, IOException {
...
HandlerResultSubscriber subscriber = new HandlerResultSubscriber(asyncContext,
isCompleted, httpRequest);
this.httpHandler.handle(httpRequest, httpResponse).subscribe(subscriber);
}