Netty 4发出警告"丢弃在管道末端到达的1个入站消息.请检查您的管道配置".这是什么意思?应该如何处理?(以前在这里复制,直到根据已接受的答案解决,但我宁愿对其含义以及管道如何工作有一般解释)
尝试最大化网络反馈,客户端管道设置如下:
pipeline.addLast("logger", new LoggingHandler(LogLevel.TRACE))
pipeline.addLast("HttpRequestEncoder", new HttpClientCodec)
pipeline.addLast("handler", new myHandler)
Run Code Online (Sandbox Code Playgroud)
所有我都在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.
Run Code Online (Sandbox Code Playgroud)
尽管日志记录设置最低,但是:
BasicConfigurator.configure
InternalLoggerFactory.setDefaultFactory(new Log4JLoggerFactory)
Run Code Online (Sandbox Code Playgroud)
在Netty 4中,服务器或客户端中使用的HTTP解码器始终为每条HTTP消息生成多个消息对象:
1 * HttpRequest / HttpResponse
0 - n * HttpContent
1 * LastHttpContent
Run Code Online (Sandbox Code Playgroud)
换一种说法:
因此,如果您的处理程序仅使用HttpRequest/HttpResponse,则其他消息将到达管道的末尾.您需要使用它们,这是您的管道"错误配置"的地方.
OTOH您可以在管道中添加HttpObjectAggregator,以便生成FullHttpRequest/FullHttpResponse消息:
pipeline.addLast( "http-aggregator", new HttpObjectAggregator( MAX_SIZE ) );
Run Code Online (Sandbox Code Playgroud)
但这意味着在调用处理程序之前加载整个请求或响应,包括正文实体.也许你不想那样,YMMV.
小智 5
Netty 4 会自动在您创建的管道上添加最后一个处理程序,如果事件到达最后一个处理程序,它将通过消息。您的最后一个入站处理程序不应触发上下文事件。
删除这个:ctx.fireChannelRead(msg);
| 归档时间: |
|
| 查看次数: |
6709 次 |
| 最近记录: |