All Products
Search
Document Center

IoT Platform:Shared subscription

Last Updated:Jun 15, 2023

This topic describes the shared subscription feature of MQTT 5.0.

Background information

MQTT is designed based on the publish-subscribe pattern. After a message is published, all subscribers can receive the message. In specific scenarios, you may want only one or several subscribers to receive specific messages. The shared subscription feature is suitable for the scenarios. A subscriber must specify a shared subscription tag and join a subscriber group when the subscriber uses the shared subscription feature.

Note

This way, only one of the subscribers of a subscriber group can receive messages.

image..png

In the preceding figure, Subscriber C and Subscriber D follow the standard process to subscribe to the demo/topic topic and Publisher A also follows the standard process to publish messages to the demo/topic topic. Subscriber A and Subscriber B use the shared subscription feature. Messages are randomly sent to Subscriber A or Subscriber B.

The shared subscription topic $share/group/demo/topic includes the following items:

  • Shared subscription tag: $share.

  • Subscriber group: group1. You must specify a value.

  • Original topic: demo/topic. You must specify a value.

IoT Platform identifies that the destination subscription is a shared subscription and belongs to a subscriber group named group1 based on the $share shared subscription tag and the subscriber group name group1. The shared subscription feature supports wildcard characters. For example, if you want to subscribe to all messages, you can subscribe to the $share/group1/# topic.

Limits

  • The shared subscription feature is available only for the gateways of Exclusive Enterprise Edition instances and Standard MQTT-based instances.

  • If multiple subscribers that use the shared subscription exist in a subscriber group, IoT Platform randomly pushes messages to one of the subscribers.

  • The shared subscription feature is available only for devices that are connected to IoT Platform over MQTT 5.0. The shared subscription feature is not available for devices that are connected to IoT Platform over MQTT 3.1 even if the devices comply with the shared subscription rules.

Scenarios

Server-side load balancing

If a large number of devices are connected and send messages to IoT Platform, multiple business servers are required to process the messages. The shared subscription feature supported by IoT Platform allows you to distribute the messages to multiple business servers. This helps implement load balancing. Business Server A and Business Server B use the same subscriber group. IoT Platform randomly pushes device-related messages to Business Server A or Business Server B, as shown in the following figure.image..png

Note

The shared subscription feature is integrated into the server-side subscription of IoT Platform. IoT Platform can send messages to business servers over Advanced Message Queuing Protocol. For more information, see Server-side subscription.

Server-side task scheduling

You can use a message to represent a task and randomly assign each task to an IoT device to implement basic task scheduling based on the shared subscription feature. For example, the devices in the following figure are robots. The business sever pushes a handling task. If one of the devices responds to the task, the shared subscription feature pushes the handling task to only one of the robots.image..png