ADC

MQTT load balancing

The Message Queuing Telemetry Transport (MQTT) is an OASIS standard messaging protocol for the Internet of Things (IoT). MQTT is a flexible and easy-to-use technology that provides effective communication within an IoT system. MQTT is a broker-based protocol and is widely used to facilitate the exchange of messages between clients and broker.

The following key benefits of MQTT make it a well-suited option for your IoT device:

  • Reliability
  • Fast response time
  • Capability to support unlimited devices
  • Publish/subscribe messaging that is perfect for many-to-many communication

IoT is the network of interconnected devices that are embedded with sensors, software, network connectivity, and necessary electronics. The embedded components enable IoT devices to collect and exchange data. The increase in use of IoT devices brings in multiple challenges for network infrastructure, with Scale being the prominent one. In a large scale deployment of IoT devices, the data generated by each IoT device needs to be analyzed swiftly. To achieve the scale requirement and efficient usage of resources, the load on the broker pool must be distributed evenly. With the support of the MQTT protocol, you can use the NetScaler appliance in IoT deployments to load balance the MQTT traffic.

The following figure depicts the MQTT architecture using a NetScaler appliance to load balance the MQTT traffic.

MQTT system

An IoT deployment with MQTT protocol has the following components:

  • MQTT broker. A server that receives all messages from the clients and then routes the messages to the appropriate destination clients. The broker is responsible for receiving all messages, filtering the messages, determining who is subscribed to each message, and sending the message to these subscribed clients. The broker is the central hub through which every message must pass.
  • MQTT client. Any device, from a micro controller up to a full-fledged server, which runs an MQTT library and connects to an MQTT broker over a network. Both publishers and subscribers are MQTT clients. The publisher and subscriber labels refer to whether the client is publishing messages or subscribed to receive messages.
  • MQTT load balancer. The NetScaler appliance is configured with an MQTT load balancing virtual server to load balance MQTT traffic.

In a typical IoT deployment, the broker (cluster of servers) manages the group of IoT devices (IoT clients). The NetScaler appliance load balances the MQTT traffic to the brokers based on various parameters, such as Client ID, topic, and user name.

Configure load balancing for MQTT traffic

For the NetScaler appliance to load balance MQTT traffic, perform the following configuration tasks:

  1. Configure MQTT/MQTT_TLS services or service groups.
  2. Configure MQTT/MQTT_TLS load balancing virtual server.
  3. Bind the MQTT/MQTT_TLS services to the MQTT/MQTT_TLS load balancing virtual server.
  4. Configure MQTT/MQTT_TLS content switching virtual server.
  5. Configure a content switching action that specifies the target load balancing virtual server
  6. Configure a content switching policy.
  7. Bind the content switching policy to a content switching virtual server that is already configured to redirect to the specific load balancing virtual server.
  8. Save the configuration.

To configure load balancing for MQTT traffic by using the CLI

Configure MQTT/MQTT_TLS services or service groups.

add service <name> <IP> <protocol> <port>
add servicegroup <ServiceGroupName> <Protocol>
bind servicegroup <serviceGroupName> <IP> <port>
<!--NeedCopy-->

Example:

add service srvc1 10.106.163.3 MQTT 1883
add servicegroup srvcg1 MQTT
bind servicegroup srvcg1 10.106.163.3 1883
<!--NeedCopy-->

Configure MQTT/MQTT_TLS load balancing virtual server.

add lb vserver <name> <protocol> <IPAddress> <port>
<!--NeedCopy-->

Example:

add lb vserver lb1 MQTT 10.106.163.9 1883
<!--NeedCopy-->

Bind the MQTT/MQTT_TLS services or service groups to the MQTT load balancing virtual server.

bind lb vserver <name> <serviceName>
bind lb vserver <name> <servicegroupName>
<!--NeedCopy-->

Example:

bind lb vserver lb1 srvc1
bind lb vserver lb1 srvcg1
<!--NeedCopy-->

Configure MQTT/MQTT_TLS content switching virtual server.

add cs vserver <name> <protocol> <IPAddress> <port>
<!--NeedCopy-->

Example:

add cs vserver cs1 MQTT 10.106.163.13 1883
<!--NeedCopy-->

Configure a content switching action that specifies the target load balancing virtual server.

add cs action <name> -targetLBVserver <string> [-comment <string>]
<!--NeedCopy-->

Example:

add cs action act1 -targetlbvserver lbv1
<!--NeedCopy-->

Configure a content switching policy.

add cs policy <policyName> [-url <string> | -rule <expression>] –action <actName>
<!--NeedCopy-->

Example:

add cs policy cspol1  -rule  “MQTT.COMMAND.EQ(CONNECT) && MQTT.CONNECT.FLAGS.QOS.eq(2)” -action act1
<!--NeedCopy-->

Bind the content switching policy to a content switching virtual server that is already configured to redirect to the specific load balancing virtual server.

bind cs vserver <virtualServerName> -policyName <policyName> -priority <positiveInteger>
<!--NeedCopy-->

Example:

bind cs vserver cs1 –policyName cspol1 -priority 20
<!--NeedCopy-->

Save the configuration.

save ns config
<!--NeedCopy-->

To configure load balancing for MQTT traffic by using the GUI

  1. Navigate to Traffic Management > Load Balancing > Virtual Servers, and create a load balancing virtual server of type MQTT or MQTT_TLS.
  2. Create a service or service group of type MQTT.
  3. Bind the service to the MQTT virtual server.
  4. Click Save.

MQTT message length limit

The NetScaler appliance treats the messages with message length greater than 65536 bytes as jumbo packets, and discard them by default. The dropmqttjumbomessage lb parameter decides whether to process the jumbo packets or not. This parameter is by default set to YES, which implies that the jumbo MQTT packets are dropped by default. If this parameter is set to NO, the ADC appliance handles even the packets with message length greater than 65536 bytes.

To configure the ADC appliance to handle jumbo packets by using CLI:

Set lb parameter –dropMqttJumboMessage [YES | NO]
<!--NeedCopy-->

Example:

set lb parameter –dropMqttJumboMessage no
<!--NeedCopy-->
MQTT load balancing