The retained message feature is defined in MQTT 3.1.1. IoT Platform supports the feature when you connect devices to IoT Platform over MQTT 5.0. This topic describes retained messages.
Retained messages
If a device or service publishes a message with a tag named Retain, the message is sent to subscribers in real time and then cached in IoT Platform. If a new subscriber appears, the message with the Retain tag is pushed to the subscriber.
Update a retained message: If you use the same topic to publish a new message, the payload of the retained message is overwritten by the payload of the new message.
Use one of the following methods to delete a retained message:
If you publish a new message that has the same topic as the retained message and whose payload is empty, the retained message is deleted.
Configure the Message Expiry Interval parameter. After the retained message expires, the retained message is deleted.
Expired sessions do not affect retained messages. Retained messages can be published regardless of the status of sessions.
Retained messages support the message expiry feature. If the content of messages expires in a period of time, such as temperature control-related messages, use the retained message feature together with the message expiry feature. For more information, see Message expiry.
A device can publish multiple messages with the Retained tag at a time. Retained message can be published regardless of whether devices are online.
Scenarios
Retained messages are suitable for scenarios in which you need to configure offline devices. For example, advertisement displays work in the daytime and hibernate at night. The devices play new advertisement content each day. In this case, the system works in a more efficient manner when the business server publishes the latest content to the devices compared to when the devices request for the latest content. To reduce power consumption, the devices hibernate to enter the offline state. In this case, the business server may fail to poll the devices to push content. You can use retained message to resolve the issue. This ensures that the devices can receive new messages the next time the devices go online.