如果异步添加处理程序,则通过 netty 通道丢失的消息
Messages lost through netty channels if handlers are added asynchronously
我观察到,如果我在收到回调后不立即放置处理程序,我就会丢失消息,例如:
有效
new jChannel.ChannelInitializer[jChannel.socket.SocketChannel] {
override def initChannel(ch: jChannel.socket.SocketChannel): Unit = {
ch.pipeline().addLast(new jHttp.HttpServerCodec())
ch.pipeline().addLast(new jHttp.HttpObjectAggregator(64))
ch.pipeline().addLast(new MyCustomRequestHandler)
}
}
不起作用
new jChannel.ChannelInitializer[jChannel.socket.SocketChannel] {
override def initChannel(ch: jChannel.socket.SocketChannel): Unit = Future { // Async Handling
ch.pipeline().addLast(new jHttp.HttpServerCodec())
ch.pipeline().addLast(new jHttp.HttpObjectAggregator(64))
ch.pipeline().addLast(new MyCustomRequestHandler)
}
}
我应该怎么做才能确保我可以异步附加侦听器。
您可以通过将 ChannelOption.AUTO_READ
设置为 false
然后将其设置为 true
来完成您想做的事情,您添加了您想要的处理程序。
你可以在 bootstrap 期间指定这些选项吗?例如
我观察到,如果我在收到回调后不立即放置处理程序,我就会丢失消息,例如:
有效
new jChannel.ChannelInitializer[jChannel.socket.SocketChannel] {
override def initChannel(ch: jChannel.socket.SocketChannel): Unit = {
ch.pipeline().addLast(new jHttp.HttpServerCodec())
ch.pipeline().addLast(new jHttp.HttpObjectAggregator(64))
ch.pipeline().addLast(new MyCustomRequestHandler)
}
}
不起作用
new jChannel.ChannelInitializer[jChannel.socket.SocketChannel] {
override def initChannel(ch: jChannel.socket.SocketChannel): Unit = Future { // Async Handling
ch.pipeline().addLast(new jHttp.HttpServerCodec())
ch.pipeline().addLast(new jHttp.HttpObjectAggregator(64))
ch.pipeline().addLast(new MyCustomRequestHandler)
}
}
我应该怎么做才能确保我可以异步附加侦听器。
您可以通过将 ChannelOption.AUTO_READ
设置为 false
然后将其设置为 true
来完成您想做的事情,您添加了您想要的处理程序。
你可以在 bootstrap 期间指定这些选项吗?例如