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
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.
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.
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.
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.
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)));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With