Glossary · Industrial communication
Retained message (MQTT)
Also known as: Retained message, Retain flag
German: Retained Message (MQTT)
In MQTT, a retained message is a message published with the retain flag set, which the broker stores as the last known value of its topic and delivers immediately to every client that subscribes to a matching topic later.
- Industrial communication
- Standards
In one sentence
A retained MQTT message is stored by the broker as the topic's last value and sent at once to every client that subscribes later.
Example
A filler publishes its machine state as a retained message, so a dashboard that starts during a shift shows Running immediately instead of waiting for the next state change.
How it applies
- Design: Retain suits state values (machine state, configuration, online status); it doesn't suit events or counters of individual occurrences, since a new subscriber would take an old event for a new one.
- Operations: The broker keeps one retained message per topic. It is removed by publishing an empty retained message to that topic, which is needed when a machine or data point is decommissioned; otherwise the stale value stays.
- Integration: A retained value may be old. Payloads should carry a timestamp so consumers can tell a current state from one left behind by a device that is offline. MQTT 5.0 lets subscribers choose whether they get retained messages at all (retain handling).
- Documentation: The documentation team documents which topics are retained, what the retained value means and how to clear it.
Retained message vs. persistent session
A retained message is stored per topic for any future subscriber. A Persistent session (MQTT) stores messages for one client that was offline.