Netty 4 でカスタム アウトバウンド メッセージ ハンドラーを試していますが、うまく動作しないようです。ハンドラーはステートメントをログに記録するだけで、チャネル パイプラインの下部に向かって追加されます。私の理解では、書き込み操作が発行されると、これらのハンドラーは下から順番に呼び出されます。カスタム ハンドラーのアイデアは、他の送信メッセージ ハンドラーより前に実行されるというものでした。
残念ながら、このログ ハンドラーをパイプラインに追加すると、ログ ステートメントが表示されますが、Netty はすぐに接続を閉じているようです。これが私のチャネル初期化子とアウトバウンド ハンドラー コードです。
HttpOutboundHandler.java
public class HttpOutboundHandler extends ChannelOutboundMessageHandlerAdapter<DefaultFullHttpResponse> {
private static final Logger logger = LoggerFactory.getLogger(HttpOutboundHandler.class);
@Override
public void flush(ChannelHandlerContext context, DefaultFullHttpResponse response)
throws Exception {
logger.debug("Executing outbound handler.");
}
}
HttpChannelInitializer.java
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("aggregator", new HttpObjectAggregator(1048576);
pipeline.addLast("compressor", new HttpContentCompressor(gzipLevel));
pipeline.addLast("outboundHandler", outboundHandler);
pipeline.addLast(eventExecutorGroup, "inboundHandler", inboundHandler);
}
最後に、これがロガー出力です。
[DEBUG] (Slf4JLogger:71) - [id: 0xbddf00cf, /0:0:0:0:0:0:0:1:57402 => /0:0:0:0:0:0:0:1:8080] ACTIVE
[DEBUG] (HttpOutboundHandler:19) - Executing outbound handler.
[DEBUG] (Slf4JLogger:71) - [id: 0x942993c1, /0:0:0:0:0:0:0:1:57403 :> /0:0:0:0:0:0:0:1:8080] INACTIVE