【问题标题】:Pipeline setup for handling fixed sized messages in Netty在 Netty 中处理固定大小消息的管道设置
【发布时间】:2013-12-21 02:43:01
【问题描述】:

在我当前的场景中,我有一个现有的非 netty 客户端,它正在向我现有的非 netty 服务器发送固定的消息大小(32 * 1024 字节)。我正在更改我的服务器以使用 Netty,我不清楚在我的业务逻辑处理程序之前我需要添加到我的管道中的处理程序。如果我要使用 SSL,那么我将首先在管道中添加 SSL 处理程序,最后添加我的业务逻辑处理程序。那么我在中间需要什么处理程序?我需要一个固定大小的 FrameDecoder(如果存在的话)吗?消息没有被任何字符分隔,所以我认为我不需要使用 DelimiterBasedFrameDecoder。我也不需要使用 StringDecoder 或 StringEncoder。

    …
    …

    pipeline.addLast("ssl", new SslHandler(engine));

    // Anything to add here for fixed sized byte[] messages??????

    // and finally add business logic handler
    pipeline.addLast("handler", new BusinessLogicHandler());
  …
  …

对于引导程序,我设置了以下选项:

   this.bootstrap.setOption("keepAlive", true);
    this.bootstrap.setOption("sendBufferSize", 32*1024);
    this.bootstrap.setOption("receiveBufferSize", 32*1024);
    this.bootstrap.setOption("tcpNoDelay", true);   

我是否也需要设置 writeBufferHighWaterMark 选项?

谢谢

【问题讨论】:

    标签: netty pipeline


    【解决方案1】:

    对于固定大小的消息,您可以在业务处理程序前面添加 FixedLengthFrameDecoder。

    见:

    http://netty.io/3.6/api/org/jboss/netty/handler/codec/frame/FixedLengthFrameDecoder.html

    【讨论】:

    • 谢谢诺曼。使用 FixedLengthFrameDecoder 时,何时应该/应该为 allocateFullBuffer 传递 true?
    • 如果为 true,则缓冲区分配在前面。所以它会直接占用内存,但会保护一些副本..
    • 好的。我让我的测试代码与 FixedLengthFrameDecoder 一起工作。谢谢诺曼。
    猜你喜欢
    • 1970-01-01
    • 2013-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-21
    • 1970-01-01
    • 2013-12-13
    相关资源
    最近更新 更多