Let me assume your MQTTDecoder
consumes ByteBuf
s and produces some MQTT message objects, and MQTTEncoder
does the opposite, which is usually the case.
Then, the ByteBuf
s your codec works with is not a Web Socket message. They need to become the payloads of the Web Socket frames. I would insert the following handlers into the pipeline:
- A
MessageToMessageDecoder
that transforms a WebSocket text (or binary) frame into aByteBuf
so thatMQTTDecoder
can consume it. The transformation should be very simple - just get the content of the Web Socket frame. - A
MessageToMessageEncoder
that transforms aByteBuf
into a Web Socket text (or binary) frame so that Netty'sWebSocketFrameEncoder
can consume it. The transformation should also be very simple - just wrap theByteBuf
encoded byMQTTEncoder
with a Web Socket frame object.
The resulting pipeline will look like the following:
HttpResponseEncoder
HttpRequestDecoder
HttpObjectAggregator(65536)
WebSocketServerProtocolHandler("/your-websocket-endpoint-path")
WebSocketFrameToByteBufDecoder
extendsMessageToMessageDecoder
ByteBufToWebSocketFrameEncoder
extendsMessageToMessageEncoder
MQTTEncoder
MQTTDecoder
MessageMetricsHandler
handler
WebSocketServerProtocolHandler
will perform necessary handshaking with your web socket client and insert WebSocketFrameEncoder
and WebSocketFrameDecoder
right before WebSocketFrameToByteBufDecoder
. The resulting pipeline after successful handshake will look like the following:
WebSocketFrameEncoder
WebSocketFrameDecoder
WebSocketFrameToByteBufDecoder
extendsMessageToMessageDecoder
ByteBufToWebSocketFrameEncoder
extendsMessageToMessageEncoder
MQTTEncoder
MQTTDecoder
MessageMetricsHandler
handler