【问题标题】:ByteBuf allocator in Reactor NettyReactor Netty 中的 ByteBuf 分配器
【发布时间】:2019-05-03 13:10:31
【问题描述】:

有没有办法在请求处理程序中获取 Reactor Netty 中使用的 ByteBuf 分配器?类似于在纯 Netty 中如何做到final ByteBufAllocator byteBufAllocator = ctx.alloc();

HttpServer.create()
        .host("0.0.0.0")
        .port(8080)
        .route(routes -> {
          routes.ws("/ws", (in, out) ->  
            // how to get the allocator here?
          });
        })

【问题讨论】:

  • 请指定服务器或客户端,您想在哪个阶段获取。
  • 感谢您的评论,澄清了问题。

标签: project-reactor reactor-netty


【解决方案1】:

您可以像这样从WebSocketOutboundHttpServerResponse 访问ByteBufAllocator

HttpServer.create()
        .host("0.0.0.0")
        .port(8080)
        .route(routes -> routes
                .ws("/ws", (in, out) -> {
                    ByteBufAllocator alloc = out.alloc();
                    // ...
                })
                .get("/path", (request, response) -> {
                    ByteBufAllocator alloc = response.alloc();
                    // ...
                })
        );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多