如何访问当前的Netty Channel
How to access the current Netty Channel
我想使用 Netty Channel.attr() 来存储 HttpRequest 以便在库例程中使用。
有人知道如何在控制器方法中找到当前频道吗?
我认为@Threadlocal 作用域可能会有所帮助,但我(还)想不出来。
所有 Netty 处理程序在您必须覆盖的方法中都有 ChannelHandlerContext ctx
参数。例如,SimpleChannelInboundHandler
:
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object message) {
Channel channel = ctx.channel();
}
我想使用 Netty Channel.attr() 来存储 HttpRequest 以便在库例程中使用。
有人知道如何在控制器方法中找到当前频道吗?
我认为@Threadlocal 作用域可能会有所帮助,但我(还)想不出来。
所有 Netty 处理程序在您必须覆盖的方法中都有 ChannelHandlerContext ctx
参数。例如,SimpleChannelInboundHandler
:
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object message) {
Channel channel = ctx.channel();
}