Домой United States USA — software Sticky Session Load Balancing (Part 2): MQTT Broker Clustering

Sticky Session Load Balancing (Part 2): MQTT Broker Clustering

203
0
ПОДЕЛИТЬСЯ

This article introduces MQTT sessions and provisioning an HAProxy load balancer in front of the EMQ X cluster for sticky-session load balancing.
Join the DZone community and get the full member experience. In the last post: Load Balancing — MQTT Broker Clustering Part 1, we introduced MQTT load balancing in general: load balancing can be applied either on the transport layer or the application layer. Now it’s time to dive into application layer load balancing, the most interesting part: sticky-session. This post consists of 2 parts. The first part is to introduce MQTT sessions and the challenges of handling sessions in a distributed MQTT broker cluster. The second part is to get our hands «dirty» by provisioning an HAProxy 2.4 load balancer in front of the EMQ X 4.3 cluster to take full advantage of the sticky-session load balancing. In order to continuously receive messages, MQTT clients usually subscribe to an MQTT broker with a long-living connection. Due to network issues or client software maintenance reasons, the connection might be broken. However, MQTT clients always want to receive all messages published even when the connection was broken. This is the reason why the MQTT broker, which is serving the client, should keep a session for the client (per the client’s request by setting the “Clean-Session” flag to false). Hence, topics to which the subscriber is currently subscribed, and messages (of QoS1 and 2) delivered to these topics, etc. are kept by the broker even when the client is disconnected. When a client has persisted session reconnects, it doesn’t have to re-subscribe the topics, cause the broker should send all the pending messages to the client. (We have previously written an article about MQTT sessions, if you are interested in more technical details about MQTT sessions, you may comment to let me know.

Continue reading...