【问题标题】:channelRead() doesn't forward message to channelRead() in next ChannelInboundHandlerchannelRead() 不会在下一个 ChannelInboundHandler 中将消息转发到 channelRead()
【发布时间】:2021-07-24 14:22:41
【问题描述】:

我有一个 netty 服务器,我在管道中添加了 2 个 ChannelOutboundHandlerAdapters,它们都有channelRead(ChannelHandlerContext ctx, Object msg),我们在其中收到一条消息。 channelRead()的定义是:

Calls ChannelHandlerContext.fireChannelRead(Object) to forward to the next ChannelInboundHandler in 
the ChanelPipeLine.

所以这意味着通过实现 channelRead(),我们的消息将自动发送到下一个 ChannelInboundHandler 的 channelRead() 方法,除非我们丢弃(释放)我们的消息。

但是,当我的服务器从客户端接收到消息时,只有一个 ChannelInboundHandler 接收到该消息,并且该消息不会转发到第二个 inboundhandler。

我必须在 channelRead() 方法中手动调用ChannelHandlerContext.fireChannelRead(Object),以便将消息转发到管道内的下一个 ChannelInboundHandler。为什么消息不会像定义中所述的那样自动转发到下一个 inboundhandler 中的 ChannelRead() 方法?

【问题讨论】:

    标签: java networking netty


    【解决方案1】:

    这是预期的...您覆盖了执行 javadoc 中所述的 channelRead(...) 方法。如果您想转发,您需要拨打super.channelRead(...)或自己拨打ctx.fireChannelRead(...)

    【讨论】:

      猜你喜欢
      • 2021-09-18
      • 2015-09-28
      • 2023-04-02
      • 2014-12-20
      • 2014-02-15
      • 2016-02-02
      • 2015-11-19
      • 2019-09-23
      • 2013-09-05
      相关资源
      最近更新 更多