Netty:netty 中通道的进程生命周期是怎样的?

Netty: What is the process lifecycle of a channel in netty?

最近在学习Netty。我遇到了一个问题,就是我在 ChannelInboundHandler.channelActive 方法中放置了一个 BlockingQueue。

针对我想从BlockingQueue中获取消息,然后将消息发送到通道,但事实是只有一条消息发送到服务器。 这是下面的代码:

@Override
public void channleActive(ChannelHandlerContext ctx) throws Exception{
   String msg = null;
   while(true){
      msg=msgQueue.take();
      ctx.writeAndFlush(Unpooled.copiedBuffer(msg, CharsetUtil.UTF_8));
   }
}

但是它不起作用,我只从 channelRead() 方法中得到一个响应。 我对 netty 生命周期的理解是错误的吗?有人可以帮我解释一下吗?

您的代码基本上 "block" 在 channelActive 中,这意味着 EventLoop 将永远无法做任何其他事情。这是不允许的。