1. Store state
The broker keeps the latest retained application message for each exact topic name. A new retained publish replaces the previous one.
See how an MQTT broker stores the latest retained message per topic and sends current state to new subscribers.
A retained message is the broker's latest saved state for one exact topic. Publish with the retain flag to store or overwrite it, subscribe later to receive matching retained state immediately, and clear stale state with an empty retained publish.
The broker keeps the latest retained application message for each exact topic name. A new retained publish replaces the previous one.
A dashboard can subscribe after the device published and still receive current state immediately, subject to the subscription filter.
A retained publish with a zero-byte payload removes the retained message for that topic. This prevents old devices from appearing alive.
Retained messages are poor event history. Use them for "pump is running" rather than "button was pressed at 09:10".
Choose whether this message should be stored as current state, sent as a live event, or used to clear a stale retained value.
Publishes a topic, payload, QoS, and retain flag.
TopicRoutes live messages and keeps retained slots by exact topic name.
Subscribes with a topic filter and maximum QoS.
FilterThe topic will have one saved retained message.
The filter matches the exact topic.
Delivery is capped by the subscriber maximum QoS.
This represents current state and helps late subscribers.
Use these cards to decide when retained messages are appropriate before using them in a system design.
The broker stores the latest retained application message for an exact topic name. It is a current-state snapshot, not a log.
When a subscription is established, the broker sends retained messages whose topic names match the subscription filter, unless MQTT 5 retain handling suppresses them.
Publish a retained message with a zero-byte payload to the exact topic. That removes the retained value for that topic.
+, and multi-level wildcards with #.These common decisions separate useful retained state from confusing stale events.
Good examples are device status, latest sensor reading, current configuration, or last known location. Late subscribers need these values immediately.
Commands, alerts, button presses, and door-open events can become misleading when replayed later. Use event topics, logs, or command acknowledgement patterns instead.
A common pattern is retained birth message "online" plus a retained Last Will "offline". Clear retained state when a device is permanently removed.
Try these short checks without leaving the page.
Set the scenario to Device state startup, press Step until the subscriber joins, then change the filter so it no longer matches. What disappears and why?
Set the scenario to Event without retain, then switch the publish action to retained. Why does the diagnosis warn against this design?