MQTT 5 Message Expiry Interval gives an Application Message a finite transport lifetime. If a broker stores a robot command while the target subscriber is offline, the time spent waiting reduces the interval that can be forwarded later. Storage never resets the clock.

This prevents a stale command from being treated as fresh merely because reliable MQTT delivery preserved it. It does not prove that a delivered command is safe, current enough for the physical process, or executed only once. Those decisions still belong to the application.

The publisher sets a lifetime

Message Expiry Interval is a Four Byte Integer PUBLISH property measured in seconds. Its value is the lifetime of the Application Message. If the property is absent, MQTT does not assign an expiry time to that message.

A broker can create separate delivery copies for matching subscribers. If the interval passes before onward delivery has started for a subscriber, the server must delete that subscriber's copy. Another subscriber that already began receiving the message can be in a different state.

For retained publications, queued QoS messages in stored Sessions, and delayed subscriber availability, the interval limits how long a copy remains eligible. It is not a broker retention policy for every message on a topic; it travels with one Application Message.

The remaining interval must shrink

When a server forwards the PUBLISH, it must set Message Expiry Interval to the received value minus the time the Application Message waited in that server. A message published with 30 seconds that waits 18 seconds is forwarded with about 12 seconds remaining, not a new 30-second interval.

This rule matters across broker bridges. Each forwarding server subtracts its own waiting time. A downstream broker receives the remaining lifetime and continues counting down. No hop should renew the original publisher's freshness budget.

Seconds are coarse and processing is not a precision real-time clock. Applications should not expect exact subsecond age measurement from this property. It is a transport expiration guard, not a replacement for a timestamp produced by a synchronized source.

Expiry and application validity differ

A joint-position command might be valid for only 100 milliseconds, while the smallest useful Message Expiry value is one second. A maintenance instruction might remain meaningful for minutes but become invalid as soon as the robot changes mode. MQTT cannot infer those process conditions.

Include an application timestamp, unique operation ID, target identity, required mode or state version, and command deadline in the payload or protected metadata. At receipt, compare them with trusted local time and current controller state. Reject commands that are expired, replayed, addressed to another asset, or based on an obsolete state version.

Message Expiry also does not cancel work after onward delivery starts. A subscriber can receive a PUBLISH just before the interval reaches zero and process it later. The receiving application must apply its own deadline when dequeuing and immediately before committing a physical action.

QoS does not override expiry

QoS 1 and QoS 2 define delivery protocol flows, ownership, and retransmission behavior. They do not make an expired message eligible for new onward delivery. Conversely, Message Expiry does not guarantee delivery within the remaining time.

A broker may acknowledge ownership of a QoS message while a subscriber copy later expires. Publishers need application acknowledgements if they must know whether a robot accepted, rejected, or executed an operation. MQTT packet acknowledgements alone report protocol progress.

Retained status and Message Expiry solve separate problems. A retained message supplies a future subscriber with the latest stored publication, but an expiry interval can remove that retained message when its lifetime ends. For robot state, publishing a new current value is usually better than letting an old retained observation appear timeless.

Design a command envelope

Set Message Expiry from the maximum useful transport delay, rounded conservatively to seconds. Use a shorter value for transient motion hints and a longer one for nonurgent maintenance data. Do not omit the property on commands merely because Session persistence and QoS are enabled.

Inside the payload, carry issued_at, expires_at, operation_id, and the expected robot state or job version. Sign or authenticate the command through the deployment's security design. Store processed operation IDs for an appropriate window so reconnect and retransmission cannot repeat a physical action.

When forwarding between systems, preserve the application deadline and subtract observed buffering time from MQTT expiry as the protocol requires. Avoid middleware that republishes a received command as a new Application Message with a full original interval unless it is intentionally creating a new command after revalidation.

Test time in the queue

Publish a message with a 30-second interval to an offline persistent Session. Reconnect the subscriber after 18 seconds and inspect the forwarded property; it should show the reduced remaining interval. Reconnect after more than 30 seconds and verify no new onward delivery begins for that copy.

Repeat through two brokers with controlled delays. Confirm each hop reduces the value. Begin delivery just before expiry, then delay the subscriber's application queue to prove why a payload deadline is still necessary.

Test clock jumps and unsynchronized robots separately. MQTT expiry is based on elapsed server time, while application timestamps depend on clock quality. Monitoring should record original and remaining expiry, broker residence time, application issue time, receive time, decision, and operation ID.

Message Expiry limits how long MQTT may keep trying to start a delivery. Its remaining value shrinks while the broker waits. Robot software should use that guard together with an independent command deadline, state preconditions, and idempotency record so reliable transport cannot turn old work into a new physical action.