如果异步添加处理程序,则消息会通过网络通道丢失

问题描述 投票:0回答:1

我观察到,如果在收到回调后不立即放置处理程序,那么我会松开例如的消息:

Works

    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)
        }
    }

我应该怎么做才能确保可以异步附加侦听器。

scala netty future
1个回答
0
投票
您可以通过将ChannelOption.AUTO_READ设置为false,然后将其设置为true,然后添加所需的处理程序来完成您想做的事情。

例如,您可以在引导过程中指定这些选项吗?>

© www.soinside.com 2019 - 2024. All rights reserved.