【问题标题】:How to create channel pool in netty?如何在netty中创建频道池?
【发布时间】:2015-06-10 14:28:00
【问题描述】:

我正在使用此示例代码创建频道:

 EventLoopGroup group = new NioEventLoopGroup();
        try {
            Bootstrap b = new Bootstrap();
            b.group(group)
             .channel(NioSocketChannel.class)
             .option(ChannelOption.SO_KEEPALIVE, true)
             .handler(new ClientInitializer());

            // Start the connection attempt.
            Channel ch = b.connect(host, port).sync().channel();

所以我在这里获得了一个频道(频道未来),但我的应用程序吞吐量会非常高,所以我认为一个频道是不够的,所以请告诉我如何创建频道池。

我正在使用 netty 4.0

【问题讨论】:

标签: java netty


【解决方案1】:

【讨论】:

  • 频道池对我来说工作正常。我面临的唯一问题是,当服务器回复客户端时,我无法在我的客户端处理程序(扩展 SimpleChannelInboundHandler)channelRead0 方法中得到它。有什么提示吗?
  • bootstrap.handler() 被 ChannelPool 覆盖。所以 b.handler(new ClientInitializer());不会有任何影响。
  • @AbhishekSen 我该如何解决这个问题?我尝试添加新的 ClientInitializer();在 ChannelPoolHandler 中 channelCreated();但我仍然遇到问题
  • @JavaMachine 看看gist.github.com/kumrigar/522e2556d2f119e26319他们是如何在 ChannelPoolHandler 的 channelCreated 回调中编写 Initializer 代码
  • 仅供参考。通道池将在 netty 5 中被弃用:github.com/netty/netty/pull/8681
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-25
  • 1970-01-01
  • 1970-01-01
  • 2020-01-19
  • 2014-02-19
  • 2019-06-16
相关资源
最近更新 更多