How it works...

In the previous recipe, the spring-boot-starter-reactor-netty has been excluded from the POM dependencies just to avoid confusion on what embedded server to use for the standalone execution. At this point, Reactor Netty server must be included in order to listen and run these threaded and functional web components of Spring 5, namely the HandlerFunction<?> and RouterFunction<?>.

It requires having a webflux@configuration class in order to implement these components. Syntax errors will arise if we apply @Controller to the class, since RouterFunction<?> and HandlerFunction<?> together take the role of the @Controller and @RequestMapping in a typical MVC scenario. In a functional web model, RouterFunction is implemented to route() all matched requests to HandlerFunction. These mappings can be a simple one or chaining of route().and.route() stream operations. Once all these components are injected into the container, the Reactor Netty server will auto-detect and listen to all these injected RouterFunction because this server required the reactive ApplicationContext to be passed as a parameter to ReactorHttpHandlerAdapter in order to build and execute all these routers.

This recipe has also proven that these functional web components can execute side-by-side with all the non-reactive @Controller since the former uses Netty while the latter executes on top of the embedded Tomcat server. Reactor Netty is a full-blown implementation of NIO specification, which is an appropriate server for executing non-blocking, asynchronous, and reactive events and services.

This recipe will be the gateway to the next chapter, which is all about microservices development.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.233.43