Based on the Netty implementation of Webscoket is relatively simple, so this is not too complicated in this lecture, to show you a class diagram, and a section to pipeline add handler, you can fully understand how the HIVEMQ to deal with, In fact, with almost all the need to use Netty to support websocket processing consistent.
Public class websockettransportchannelinitializer { Public Static Final intMax_content_length =65536;Private FinalWebsocketlistener Listener; Public Websockettransportchannelinitializer(Websocketlistener Listener) { This. Listener = Listener; } Public void Initchannel(Channel Channel) {//Add HTTP protocol encoding/decodingChannel.pipeline (). Addbefore (Pipelines.all_channel_group_handler, Pipelines.http_server_codec,NewHttpservercodec ());//Add HttpRequest message aggregatorChannel.pipeline (). Addafter (Pipelines.http_server_codec, Pipelines.http_object_aggregator,NewHttpobjectaggregator (max_content_length));//Add WebsocketserverprotocolhandlerString Path = This. Listener.getpath (); String subprotocols = Getsubprotocols ();BooleanAllowExtensions = This. Listener.getallowextensions (); Channel.pipeline (). Addafter (Pipelines.http_object_aggregator, Pipelines.websocket_server_protocol_handler,NewWebsocketserverprotocolhandler (Path, Subprotocols, AllowExtensions, Integer.max_value));//Add WebSocket byte code handlerChannel.pipeline (). Addafter (Pipelines.websocket_server_protocol_handler, pipelines.websocket_binary_frame_ HANDLER,NewWebsocketbinaryframehandler ());//Add WebSocket frame type handlerChannel.pipeline (). Addafter (Pipelines.websocket_binary_frame_handler, pipelines.websocket_continuation_frame_ HANDLER,NewWebsocketcontinuationframehandler ());//Add websocket text handlerChannel.pipeline (). Addafter (Pipelines.websocket_binary_frame_handler, Pipelines.websocket_text_frame_handler,NewWebsockettextframehandler ());//Add MQTT message convert to WebSocketChannel.pipeline (). Addafter (Pipelines.websocket_text_frame_handler, Pipelines.mqtt_websocket_encoder,NewMqttwebsocketencoder ()); }@VisibleForTestingString Getsubprotocols () {returnJoiner.on (","). Join ( This. Listener.getsubprotocols ()); }}
MQTT Exchange Group: 221405150
MQTT---hivemq source detailed (eight) netty-websocket