Search code examples
micronaut

How to access the current Netty Channel


I would like to use the Netty Channel.attr() to store the HttpRequest for use in library routines.

Anyone know how to find the current channel while in a controller method?

I thought @Threadlocal scope might help, but I can't figure it out (yet).


Solution

  • All Netty handlers have ChannelHandlerContext ctx parameter in method you have to override. For example, SimpleChannelInboundHandler:

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object message) {
        Channel channel = ctx.channel();
    }