who calls subscribe on Flux or Mono in reactive webapplication

前端 未结 2 524
死守一世寂寞
死守一世寂寞 2020-12-20 17:02

I am looking at some examples of reactive web applications and i am seeing them like this

@RequestMapping(value = \"/{id}\", method = RequestMethod.GET)
@Res         


        
相关标签:
2条回答
  • 2020-12-20 17:55

    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.

    0 讨论(0)
  • 2020-12-20 17:57

    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);
    }
    
    0 讨论(0)
提交回复
热议问题