Netty 如果使用通道池,则添加侦听器/返回future以获取http响应

Netty 如果使用通道池,则添加侦听器/返回future以获取http响应,netty,Netty,我想实现一个带有连接池的简单异步http客户端 这是我的连接池映射 channelPool = new AbstractChannelPoolMap<InetSocketAddress, ChannelPool>() { @Override protected ChannelPool newPool(InetSocketAddress key) { Bootstrap bootstrap = getBootstrap().rem

我想实现一个带有连接池的简单异步http客户端

这是我的连接池映射

channelPool = new AbstractChannelPoolMap<InetSocketAddress, ChannelPool>() {
        @Override
        protected ChannelPool newPool(InetSocketAddress key) {
            Bootstrap bootstrap = getBootstrap().remoteAddress(key);
            return new FixedChannelPool(bootstrap, nett4HttpClientInitializer, maxConnectionsPerHost);
        }
    };
问题是,如果我向netty4HttpClientInitializer添加SimpleChannelInboundHandler,我认为它将被调用pool.acquire()的每个线程共享

你能帮我把SimpleChannelInboundHandler变成无状态吗? channelRead0中的侦听器?执行任务-channelContext.executor().submit()

我从netty事件循环外部调用pool.acquire()。我想通过HttpResponse获得未来

public void channelCreated(Channel ch) throws Exception {
        SocketChannel channel = (SocketChannel) ch;
        channel.config().setKeepAlive(true);
        channel.config().setTcpNoDelay(true);
        if (connectTimeout > 0) {
            channel.config().setConnectTimeoutMillis(connectTimeout);
        }
        ChannelPipeline pipeline = channel.pipeline();
        // Enable HTTPS if necessary.
        if (sslContext != null) {
            pipeline.addLast(sslContext.newHandler(channel.alloc()));
        }
        if (proxy != null) {
            if (proxyUser != null && !proxyUser.trim().isEmpty()) {
                pipeline.addLast(new HttpProxyHandler(proxy, proxyUser, proxyPassword));
            } else {
                pipeline.addLast(new HttpProxyHandler(proxy));
            }
        }
        pipeline.addLast(new HttpClientCodec());
        pipeline.addLast(new HttpContentDecompressor());
        pipeline.addLast(new HttpObjectAggregator(maxResponseSize));
        if (readTimeout > 0) {
            pipeline.addLast(new ReadTimeoutHandler(readTimeout, TimeUnit.MILLISECONDS));
        }}