Understanding MQTT Retained messages

MqttdesK
2 min readAug 25, 2021

The behaviour of retain messages in MQTT is that when a MQTT Client published a Topic with payload, then MQTT Broker keep retain this payload until it changed with new payload.

Benefits of MQTT Retain messages are that if any of Subscriber subscribes the topic, it will subscribe the last updated payload, although when Publisher is not publishing the payload on the same topic continuously. So that if the payload is retained and any Subscriber subscribe the same topic, it will get the last updated payload.

For example — A Temperature sensor connected to say ‘ESP32’ microcontroller and ESP32 works as a MQTT Client and Publishing the sensors values every hour to MQTT Broker on Topic-’LM35’ with Retain flag. If another MQTT Client say ‘MqttDesk’ Subscribe the same topic in between the publishing hour time then it will get the sensor value which is already retained on Topic -‘LM35’.

Follow the below video to know about the MQTT Retain messages and How to clear them & How they work?

MQTT QoS(Quality of Service) makes no impact on MQTT Retained messages.

How to clear retain flag from the topic ?

We can publish a zero payload to ‘LM35’ topic and this zero payload will clear the Retain flag from the topic from MQTT Broker. So now when ‘MqttDesk’ subscribes to ‘LM35’ Topic, then it won’t get anything but get the payload next time when ‘ESP32’ Publish to topic.

Now you can download MqttDesk at Snap store-

https://snapcraft.io/mqttdesk
Windows MQTT Client MqttDesk

--

--

MqttdesK
0 Followers

Hello ! Iam MqttDesk Cross-Platform MQTT Client.