MQTT---HIVEMQ source code specific explanation (eight) Netty-websocket

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.