MQTT 5.0 topic aliases replace string-based topics with numeric identifiers, reducing packet size and saving bandwidth for constrained IoT devices.
Background information
IoT devices that connect over cellular networks are often sensitive to traffic and power consumption. For example, battery-powered temperature sensors in agricultural scenarios may have a monthly traffic limit of only a few megabytes. Smaller data packets help reduce power and traffic consumption. Topic aliases replace string topics with numbers to reduce message packet size. A topic string typically contains business properties and can be tens of bytes long, sometimes even longer than the payload itself. A topic alias replaces this string with a number that is only four bytes long.
Limits
-
Topic aliases rely on a mapping between topics and aliases. Both the device and Alibaba Cloud IoT Platform must maintain this mapping. The mapping is created when an alias is first used and removed when the connection is closed. A device must re-establish the mapping after reconnecting.
-
Aliases must be unique. Each topic maps to exactly one alias.
-
Do not publish messages concurrently when using topic aliases. Concurrent messages may be lost due to the distributed nature of the cloud.
-
Each device supports a maximum of 20 topic aliases for both upstream and downstream messages.
Scenarios
The following figure uses a temperature sensor to show how topic aliases work. In this example, Message A and Message B have the same payload. Message A includes both a topic and an alias. In Message B, the topic is empty and replaced by the alias. The topic /sys/product_name/device_001/farmland_1234/sensors/temperature is more than 60 bytes long. Using a topic alias saves this bandwidth.