Распределитель ByteBuf в Reactor Netty - PullRequest
0 голосов
/ 03 мая 2019

Есть ли способ получить доступ к распределителю ByteBuf, используемому в Reactor 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 Ответ

1 голос
/ 05 мая 2019

Вы можете получить доступ к ByteBufAllocator из WebSocketOutbound или 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();
                    // ...
                })
        );
...