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 HiveMQ.
Joule supports this feature by providing a dedicated DSL attribute, lwt notifier. The feature is applicable for both the source and sink transports.
Example
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.
mqttPublisher:...lwt notifier:topic:sensors/groundfloor/kitchen/statusmessage:"Humidity Controller publisher disconnected from broker"retain:trueinterval delay:7qos:2
Notifier attributes schema
These attributes provide the configuration parameters to send publisher disconnection notifications to connected subscribers.
Attribute
Description
Data Type
Required
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.