← Back to the chapter · Next detail →

Technical detail · MQTT Publish-Subscribe Basics

Retained snapshot freshness and session queues

Message Queuing Telemetry Transport (MQTT) can supply a late listener with stored state that needs freshness and delivery checks. A topic names a message’s route, a broker routes messages, and a subscriber is a client registered to receive matching publications. A payload is the carried application content. A retained message is a last-known snapshot stored for a topic. A new matching subscription can receive that snapshot. Joining after an ordinary, non-retained publication does not by itself promise a replay.

Suppose the operations screen joins after the boiler reading was sent. A retained temperature can give it a last-known value, but last-known does not mean current. The screen needs the reading’s timestamp or age to judge freshness. A stale reading is too old for its intended use; receiving it now does not make the measurement new.

The same distinction matters more for an instruction. A retained command can reach a device when it makes a new matching subscription. Before using retained state for commands, review the command’s age and effect. The application needs a policy for stale commands. Topic matching alone cannot make it safe to act on.

Retained state belongs to a topic. A session holds client-related state, such as subscriptions and eligible queued messages. Its settings and the broker’s limits determine what may wait while a client is offline. A retained snapshot and an offline queue answer different questions; neither is a promise of a complete history.

← Back to the chapter · Next detail →