Netty 4发出警告“丢弃到达流水线末尾的%1入站消息。请检查您的流水线配置”。什么意思?该如何处理呢?(之前的reproduced here直到按照公认的答案解决,但我更希望得到关于它的含义和管道如何工作的一般解释)
为了最大限度地获得网络反馈,客户端管道设置如下:
pipeline.addLast("logger", new LoggingHandler(LogLevel.TRACE))
pipeline.addLast("HttpRequestEncoder", new HttpClientCodec)
pipeline.addLast("handler", new myHandler)当Netty发送两条http消息并被服务器端成功接收和确认时,我在客户端得到的所有记录是:
12 [main] DEBUG io.netty.util.internal.InternalLoggerFactory - Using Log4J as the default logging framework
164 [nioEventLoopGroup-1-2] DEBUG io.netty.channel.nio.SelectorUtil - Using select timeout of 500
164 [nioEventLoopGroup-1-2] DEBUG io.netty.channel.nio.SelectorUtil - Epoll-bug workaround enabled = false
229 [nioEventLoopGroup-1-2] WARN io.netty.channel.DefaultChannelPipeline - Discarded 1 inbound message(s) that reached at the end of the pipeline. Please check your pipeline configuration.
230 [nioEventLoopGroup-1-2] WARN io.netty.channel.DefaultChannelPipeline - Discarded 1 inbound message(s) that reached at the end of the pipeline. Please check your pipeline configuration.而日志记录的设置最低限度如下:
BasicConfigurator.configure
InternalLoggerFactory.setDefaultFactory(new Log4JLoggerFactory)发布于 2013-03-23 00:36:59
在Netty 4中,服务器或客户端中使用的HTTP解码器总是为单个HTTP消息生成多个消息对象:
1 * HttpRequest / HttpResponse
0 - n * HttpContent
1 * LastHttpContent换句话说:
因此,如果您的处理程序仅使用HttpRequest/HttpResponse,则其他消息将到达管道的末尾。你需要使用它们,这就是你的管道被“错误配置”的地方。
你可以添加一个HttpObjectAggregator到你的管道中,这样就可以生成FullHttpRequest/FullHttpResponse消息:
pipeline.addLast( "http-aggregator", new HttpObjectAggregator( MAX_SIZE ) );但这意味着整个请求或响应,包括主体实体,都是在调用处理程序之前加载的。也许你不想这样,YMMV。
发布于 2014-11-25 04:31:27
Netty 4自动在创建的管道上添加最后一个处理程序,如果事件到达这个最后一个处理程序,它将通过消息。您的最后一个入站处理程序不应激发上下文事件。
去掉这个: ctx.fireChannelRead(msg);
发布于 2015-08-26 14:47:52
@eskatos是正确的,管道的处理程序基于类型匹配进行处理,例如,SimpleChannelInboundHandler<HttpContent>将只处理HttpContent,如果你还没有处理HttpReponse (将SimpleChannelInboundHandler<HttpReponse>添加到你的管道中),Netty将警告: Content-Length:到达管道尾部的<length>。请检查您的管道配置。
因此,解决方案是将相应的ChannelInboundHandler/ChannelOutboundHandler添加到您的管道中。
但是您首先需要知道类型处理程序缺少什么:找到DefaultChannelPipeline的channelRead方法并调试到其中,以获得包含消息缺少内容的msg.content().toString()。
还有一件事,前面提到的用于启用调试日志的@Norman Maurer不起作用,因为channelRead方法不记录msg内容中的内容。
下面是DefaultChannelPipeline的channelRead方法(Netty4.1):
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
try {
logger.debug(
"Discarded inbound message {} that reached at the tail of the pipeline. " +
"Please check your pipeline configuration.", msg);
} finally {
ReferenceCountUtil.release(msg);
}
}https://stackoverflow.com/questions/15242793
复制相似问题