Reactor Netty中的ByteBuf分配器

时间:2019-05-03 13:10:31

标签: project-reactor reactor-netty

有没有办法在请求处理程序中获取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?
          });
        })

1 个答案:

答案 0 :(得分:1)

您可以像这样从ByteBufAllocatorWebSocketOutbound访问HttpServerResponse

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();
                    // ...
                })
        );