Trace when an MQTT broker publishes a stored Will Message and when it must cancel it.
animation
mqtt
protocols
reliability
Learner-ready MQTT Last Will workbench with scenario presets, step/play controls, keep-alive and Will Delay feedback, retained status behavior, birth-message pairing, MQTT 5 disconnect nuance, source links, and desktop/mobile visual verification.
Last WillKeep AliveWill DelayRetained status
MQTT Last Will Workbench
Trace the Will Message stored during CONNECT, then compare normal DISCONNECT, network failure, keep-alive timeout, MQTT 5 disconnect-with-will, and delayed reconnect cancellation.
Will topicdevices/pump-7/status
Broker decisionstore will
Detection pathconnection alive
Subscriber outputonline
TryChoose Network loss, Keep Alive 30 s, Will Delay 10 s, retained offline, QoS 1, then reconnect before the delay expires.
ObserveKeep-alive timeout detects loss near 45 s, but Broker decision cancels the Will if the same session resumes inside the extra 10 s delay.
ExplainThe broker stores Will properties at CONNECT and publishes only after an ungraceful trigger; graceful DISCONNECT cancels it, while MQTT 5 delay permits session recovery first.
pump-7 connects with a Will Message and then publishes an online birth message.
Event source
The device is connected and sending MQTT control packets within the Keep Alive window.
Broker decision engine
The broker stores the Will Message from CONNECT and clears it only when protocol rules say it should.
Will topicdevices/pump-7/status
Will payload{"status":"offline"}
QoS 1 + retainedPublished by the broker only when the trigger condition is met.
C
clientbrokersubscribers
Will is stored, connection is alive
No Will Message is published while the connection is healthy.
Session stateWill properties are associated with the network connection and server-side session state.
Retained statusRetained birth/will messages make new subscribers see the current presence state.
Status subscribers
Dashboards subscribe to devices/+/status and currently see pump-7 as online.
Routing trace
Step through CONNECT, birth message, fault, detection, delay, and subscriber update.
Will is armed, not published
The broker stores the Will Message during CONNECT. Because the client is still connected, subscribers should see the retained birth message instead of the offline will.
Quick reference
Will is configured in CONNECT
The client sets Will Flag, Will QoS, Will Retain, Will Topic, and Will Payload.
MQTT 5 can add Will Delay Interval, Message Expiry, Content Type, User Properties, and related will properties.
The broker stores the will until a rule publishes or discards it.
When it publishes
Unexpected network close, protocol error, I/O failure, or Keep Alive timeout can publish the will.
MQTT 5 DISCONNECT with reason code 0x04 can explicitly request will publication.
Will Delay can postpone publication and allow fast reconnect cancellation.
When it does not
Normal DISCONNECT discards the stored will.
Reconnect before Will Delay expires can prevent the offline message.
LWT is presence detection, not an instant heartbeat.
Technical accuracy notes
Keep Alive timing
The server is allowed to close the connection if it does not receive MQTT control packets within one and a half times the Keep Alive interval. The will is considered after that close plus any Will Delay.
Retained birth/will pair
A retained online birth message followed by a retained offline will is a common presence pattern. The will retain flag controls whether new subscribers see the offline state later.
QoS still matters
The Will Message uses its configured QoS when the broker publishes it. QoS can affect acknowledgments and duplicates, but it does not make presence detection instantaneous.