Last Will and Testament
Last updated
Was this helpful?
Last updated
Was this helpful?
Last Will and Testament (LWT) is a powerful feature in MQTT that allows clients to specify a message that will be automatically published by the broker on their behalf, if or when an unexpected disconnection occurs.
It provides a reliable means of communication and ensures that clients can gracefully handle disconnections without leaving topics in an inconsistent state. This feature is particularly valuable when clients must notify others of their unavailability or convey important information upon an unexpected disconnection, reference .
Joule supports this feature by providing a dedicated DSL attribute, lwt notifier
. The feature is applicable for both the source and sink transports.
In this example, the lwt notifier
feature is configured for the MQTT publisher.
It specifies that if the publisher disconnects unexpectedly, a message will be sent to the topic sensors/groundfloor/kitchen/status
to notify subscribers of the disconnection.
The message will indicate that the Humidity Controller publisher disconnected from broker
and the publisher will wait for a delay of 7 seconds before sending this notification.
These attributes provide the configuration parameters to send publisher disconnection notifications to connected subscribers.
topic
Topic to sent status message on to
String
message
Message to send to consumers when publisher no longer exists
String
Default: "Publisher disconnected from broker"
interval delay
The Server delays publishing the Client's Will Message until the Will Delay Interval has passed or the Session ends, whichever happens first.
Long
Default: 5 seconds
retain
If message is retained
Boolean
Default: true
qos
Quality of service
Integer
Default: 1