SOURCE Blog Address: http://blog.csdn.net/pipinet123
MQTT Exchange Group: 221405150
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 to join the handler, you can fully understand how HIVEMQ handled, In fact, almost all of them need to use Netty to support WebSocket's processing consistency.
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvcglwaw5lddeymw==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast "alt=" WebSocket "title=" ">
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 ());//Join HttpRequest message aggregatorChannel.pipeline (). Addafter (Pipelines.http_server_codec, Pipelines.http_object_aggregator,NewHttpobjectaggregator (max_content_length));//Join 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));//Join WebSocket bytecode handlerChannel.pipeline (). Addafter (Pipelines.websocket_server_protocol_handler, pipelines.websocket_binary_frame_ HANDLER,NewWebsocketbinaryframehandler ());//Join WebSocket frame Type handlerChannel.pipeline (). Addafter (Pipelines.websocket_binary_frame_handler, pipelines.websocket_continuation_frame_ HANDLER,NewWebsocketcontinuationframehandler ());//Join WebSocket text HandlerChannel.pipeline (). Addafter (Pipelines.websocket_binary_frame_handler, Pipelines.websocket_text_frame_handler,NewWebsockettextframehandler ());//Join 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---HIVEMQ source code specific explanation (eight) Netty-websocket