Overview
The MQTT was designed to support messaging in low bandwidth scenarios; by using Topic Aliases, we can reduce the bandwidth requirements even further.
MQTT Topic Alias
The Topic Alias is a property introduced in the MQTTv5. It reduces the network bandwidth required for the MQTT communication.
A Topic Alias is an integer value that is used to identify the Topic instead of using the Topic Name. This reduces the size of the PUBLISH packet and is useful when the Topic Names are long and/or we work with extremely limited network bandwidth.
The Sender (Client) decides whether to use a Topic Alias and chooses the integer value. It sets a Topic Alias mapping by including a non-zero length Topic Name and a Topic Alias in the PUBLISH packet.
|
|
The Receiver (Broker) processes the PUBLISH as normal, but also sets the specified Topic Alias mapping to this Topic Name.
In further communication, the Topic Name is omitted.
⚠️Very important: Topic Alias mappings exist only within a Network Connection and last only for the lifetime of that Network Connection.
Mosquitto example
Eclipse Mosquitto is an open source (EPL/EDL licensed) message broker, you can download it from this link.