All Products
Search
Document Center

ApsaraMQ for MQTT:Topic aliases

Last Updated:Aug 23, 2024

This topic describes the topic alias feature of Message Queuing Telemetry Transport (MQTT) 5.0.

Feature description

Topic alias is a new feature introduced into MQTT 5.0. The feature allows you to use short integer values to replace topic paths for communication between clients and brokers. This reduces transmission loads and bandwidth consumption and improves transmission efficiency.

Limits

  • Up to 30 topic aliases are supported by a server in each connection. If the number of topic aliases in messages sent by the client to the server exceeds 30, the connection is closed and a topic name error is reported.

  • The client can declare up to 30 supported topic aliases to the server in each connection. If the number of declared topic aliases exceeds 30, topic aliases are not specified when the server pushes messages to the client.

  • Each topic alias must be unique and correspond to a topic in a connection.

  • The mappings between topic aliases and topics take effect only for the current connection. The topic aliases in a new connection established after disconnection may be different.

Usage notes

  • You cannot specify a value of 0 for the Topic Alias parameter.

  • The value that you specify for the Topic Alias parameter in the PUBLISH packet of the client cannot be greater than the value of the Topic Alias Maximum parameter returned in the CONNACK packet of the server. If the value of the Topic Alias parameter that you specify in the CONNECT packet is greater than 0 but less than or equal to the value of the Topic Alias Maximum parameter, the client must accept all topic aliases.

  • Topic alias mappings on the client may not be identical to the topic alias mappings on the server. For example, the topic alias 1 in the PUBLISH packet of the client and the topic alias 1 in the PUBLISH packet of the server may correspond to different topics.

Scenarios

  • Limited bandwidth: If the network bandwidth of the device is limited, you can use the topic alias feature to reduce the amount of data required to send a message.

  • High-frequency message publishing: When a client frequently publishes messages to the same topics, you can use the topic alias feature to reduce the number of redundant messages that are sent. For example, you can use the feature in stock market tracking and Internet of Things (IoT) data collection systems in which a large number of messages are sent every second.

  • Energy savings: For a battery-powered device, such as a remote monitoring site or a mobile device, the topic alias feature can help reduce the amount of data transmitted over wireless networks. This helps extend the battery life of the device.

  • Resource-limited devices: For embedded and IoT devices whose hardware resources are limited, short topic aliases can help accelerate message processing and reduce memory consumption.

The topic alias feature of MQTT 5.0 optimizes message transmission and network environment in various scenarios and improves the efficiency and flexibility of IoT devices and real-time communication applications.

Example

You assign the topic alias 1 to a topic named home/groundfloor/livingroom/temperature. In the subsequent messaging process, you need to reference only 1.

Sample code for the first PUBLISH packet:

Topic Name: home/groundfloor/livingroom/temperature
Topic Alias: 1
Payload: 22°C

Sample code for the subsequent PUBLISH packets:

Topic Alias: 1
Payload: 23°C

In the preceding example, you no longer need to include the full topic name in the subsequent PUBLISH packets after you use the topic alias feature.