我从客户端发送消息,但是服务器始终对其进行处理。 即我希望该服务器将异步读取所有消息,但不是将该服务器放置在队列中。 在ChannelPipeline中,我添加了4个处理程序,最后一个处理程序包含业务逻辑(从DB中获取数据,对其进行后处理等)。
class ChannelInitializer extends ChannelInitializer<SocketChannel> {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(sslHandlerFactory.createSslHandler(ch));
pipeline.addLast(messageDecoderProvider.get());
pipeline.addLast(messageEncoderProvider.get());
pipeline.addLast(channelHandler);
}
}
此外,我尝试将DefaultEventLoopGroup传递给方法ChannelPipeline.addLast(...),但结果是相同的。
class ChannelInitializer extends ChannelInitializer<SocketChannel> {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
DefaultEventLoopGroup defaultEventLoopGroup = new DefaultEventLoopGroup(10);
pipeline.addLast(defaultEventLoopGroup, sslHandlerFactory.createSslHandler(ch));
pipeline.addLast(defaultEventLoopGroup, messageDecoderProvider.get());
pipeline.addLast(defaultEventLoopGroup, messageEncoderProvider.get());
pipeline.addLast(defaultEventLoopGroup, channelHandler);
}
}