Available since TBMQ Version 2.0 |
In MQTT, a subscription is a mechanism that allows clients to receive messages directed to specific topics. When a client subscribes to a topic, it expresses its interest in receiving all messages published to that topic.
Subscriptions table
On the Subscriptions page you may observe, analyze or filter all subscriptions on the broker. The table contains the following information about each subscription:
- Client ID. The identifier of the client that is the owner of the subscription.
- Topic filter. The MQTT topic filter.
- QoS. Quality of Service of the subscription.
- Retain as Published. When true, messages forwarded using this subscription keep the RETAIN flag they were published with.
- Retain Handling This option determines how the broker should handle retained messages when the client subscribes to a topic.
- 0 - send retained messages at subscription time;
- 1 - send retained messages at subscription time if the subscription does not already exist;
- 2 - do not send retained messages at subscription time.
- No local. When true, the broker will not forward messages from this client back to the connection on which this subscription was made.
- Subscription Identifier. It is a unique numerical value that assigned to subscription, allowing the client to distinguish messages from different subscriptions.
Manage subscriptions
You can easily add, remove or edit subscriptions from the ‘Session details’ window.
- Open the ‘Subscriptions’ page in the left-hand menu.
- Click on the icon button ‘Session details’.
- Click on the tab ‘Subscriptions’ to manage session subscriptions.
- Add, edit or delete client subscriptions.
- Click ‘Update’ to save changes.
Clearing Empty Subscription Nodes
Subscriptions in the broker are stored in the memory using the Trie data structure, which is known for its efficient searching capabilities. The Trie (also called a prefix tree) is a tree-based data structure that allows for quick retrieval of information based on a key or a sequence of characters.
The Trie organizes the topic filters in a hierarchical manner, where each node represents a topic level from the topic filter. By using the Trie data structure, the broker can quickly locate and retrieve client subscriptions based on the topic name provided by a published message. This ensures that clients receive the published messages they are interested in without significant delays, contributing to improved performance and responsiveness of the broker.
When a client subscription is deleted (unsubscribed), the broker removes the data from its memory and marks the node as empty. Over time, if many subscriptions are deleted, there may be many empty nodes left in the broker’s memory. These empty nodes can cause inefficiencies and waste memory resources.
Clearing empty subscription nodes frees up memory resources and can improve the performance of the broker, as it can process subscription matching more quickly when there are fewer empty nodes to search through.
To Clear empty subscription nodes click on the button ‘Clear empty subscription nodes’ in the top right corner (the trash button) and confirm action.
Additionally, the broker is configured to clear empty subscription nodes by a scheduler. This is controlled by the following environment variables:
MQTT_SUB_TRIE_CLEAR_NODES_CRON
and MQTT_SUB_TRIE_CLEAR_NODES_ZONE
.