Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure netty in spring boot 2

By default spring web flux uses netty which is single threaded event loop. How to configure spring boot so that a thread will be created for each core.

Thanks,

Lokesh

like image 811
Lokesha S Avatar asked Oct 04 '17 14:10

Lokesha S


People also ask

Does spring boot use Netty?

spring-boot-starter-reactor-netty is required to use the WebClient class, so you may need to keep a dependency on Netty even when you need to include a different HTTP server.

What is HTTP 2 support in spring boot?

http2. enabled configuration property. This support depends on the chosen web server and the application environment, since that protocol is not supported out-of-the-box by JDK8. Note. Spring Boot does not support h2c , the cleartext version of the HTTP/2 protocol.

What is spring Netty?

Definition of Spring Boot Netty. It is an event-driven application framework that was used in-network, it will provide the HTTP, UDP, and non-blocking server and client. As per the name spring boot, netty is based on the netty framework, it is also known as the non-blocking input and output (NIO) framework.

What is a Netty port?

Netty is a NIO client server framework which enables quick and easy development of networkServerInitializerFactory applications such as protocol servers and clients. Netty greatly simplifies and streamlines network programming such as TCP and UDP socket server.


1 Answers

As described in the Spring Boot reference documentation, you can customize the Reactor Netty web server with a NettyServerCustomizer.

Here's an example with Spring Boot 2.1:

@Component
public class MyNettyWebServerCustomizer
        implements WebServerFactoryCustomizer<NettyReactiveWebServerFactory> {

    @Override
    public void customize(NettyReactiveWebServerFactory factory) {
        factory.addServerCustomizers(new EventLoopNettyCustomizer());
    }
}

class EventLoopNettyCustomizer implements NettyServerCustomizer {

    @Override
    public HttpServer apply(HttpServer httpServer) {
        EventLoopGroup eventLoopGroup = //...;
        return httpServer.tcpConfiguration(tcpServer ->
                tcpServer.bootstrap(serverBootstrap
                        -> serverBootstrap.group(eventLoopGroup)));
    }
}
like image 169
Brian Clozel Avatar answered Oct 26 '22 15:10

Brian Clozel