$linuxjunkies
>

retained message

also: retained publish, last known good value, LKG

A message published to an MQTT broker with the retain flag set, which the broker stores and automatically delivers to any new subscribers of that topic.

In MQTT (Message Queuing Telemetry Transport), a retained message is the last message published to a topic that the broker keeps in memory. When a new client subscribes to that topic, it immediately receives the retained message without having to wait for a publisher to send a new one.

This is useful for providing the current state of a device or sensor to newly connected clients. For example, a temperature sensor publishes its latest reading with the retain flag set; any client connecting later will immediately know the current temperature rather than having to wait for the next reading.

A retained message persists on the broker until it is replaced by a new retained message on the same topic, or until the broker is restarted (unless persistence is configured). Publishing an empty retained message effectively clears the retained state for that topic.

Related terms