'How to configure child group using NettyServerCustomizer?
I upgraded netty version and found out that TcpServer's bootstrap method had been removed from the version I had previously. I not able to figure out how to convert my existing code using new netty lib.
factory.addServerCustomizers((NettyServerCustomizer) httpServer -> {
httpServer
.tcpConfiguration(tcpServer ->
tcpServer
.bootstrap(serverBootstrap ->
serverBootstrap
.group(parentGroup, childGroup)
.channel(NioServerSocketChannel.class)
)
);
I can do httpServer.runOn(parentGroup)
but can't figure out how to configure childGroup with that. Any ideas?
Solution 1:[1]
You can use the code below as a replacement:
LoopResources loop =
new LoopResources() {
@Override
public EventLoopGroup onServer(boolean useNative) {
return childGroup;
}
@Override
public EventLoopGroup onServerSelect(boolean useNative) {
return parentGroup;
}
};
httpServer.runOn(loop, false);
This is if you want to use some specific implementation for the EventLoopGroup
.
If your requirement is just to use NIO then you can use the code below:
LoopResources loop = LoopResources.create("my-loop", parentGroupNumThreads, childGroupNumThreads, true);
server.runOn(loop, false);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Violeta Georgieva |