java - 获取最后一个 ChannelInboundHandler 的结果
问题描述
我正在编写基于 Netty 的客户端应用程序。我想提取管道中最后一个处理程序的结果。
管道是用
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null)
p.addLast("ssl", sslCtx.newHandler(ch.alloc()));
p.addLast("client", new HttpClientCodec());
p.addLast("decompressor", new HttpContentDecompressor());
p.addLast("aggregator", new HttpObjectAggregator(HTTP_OBJECT_MAX_SIZE));
p.addLast("my-handler", new MyApiResponseChannelHandler());
}
最终实现在哪里
public class MyApiResponseChannelHandler extends MessageToMessageDecoder<FullHttpResponse> {
@Override
protected void decode(ChannelHandlerContext ctx, FullHttpResponse msg, List<Object> out) throws Exception {
out.add(msg.status().code() + " - " + msg.status().reasonPhrase());
}
}
我想了解添加到out
列表中的字符串。
发送请求时,我添加了如下代码
ch.writeAndFlush(request).addListener( f -> logger.info("Got value {}", f.get()));
并且
ch.closeFuture().addListener( f -> logger.info("Got value {}", f.get()));
他们都给了我一个null
价值。
我怎样才能得到最后的结果ChannelInboundHandler
?我会对未来感到满意,但我似乎无法找到合适的未来。
解决方案
推荐阅读
- mysql - Plesk 数据库 - 错误:SQLSTATE[HY000] [2002] 无法建立连接,因为目标机器主动拒绝它
- python - Python 从 Windows 上的命令行使用 -f 输入文件
- javascript - 如何从数据中连续显示多个图像。在本机反应
- linux - Flutter:动画严重减慢磁盘写入速度
- r - 从ggplot中的字符串创建线型
- postgresql - 如何处理“。” 在字段名 Postgresql(潜望镜)
- android - Android Kotlin 编译器中使用了哪个 Kotlin 元数据版本
- wordpress - 通过 wordpress 中的 html 小部件实现 Sizmek 印象标签并在 url 中创建 cachebuster
- php - 在 Symfony 4.4 流程组件中将参数作为数组传递
- android - 如何从 Android 读取 Firebase 远程配置模板版本?