> For the complete documentation index, see [llms.txt](https://docs.fractalworks.io/joule/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fractalworks.io/joule/components/connectors/sinks/mqtt/last-will-and-testament.md).

# Last Will and Testament

## Overview

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.&#x20;

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](https://www.hivemq.com/blog/mqtt-essentials-part-9-last-will-and-testament/).&#x20;

Joule supports this feature by providing a dedicated DSL attribute, `lwt notifier`. The feature is applicable for both the source and sink transports.&#x20;

### **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.

```yaml
mqttPublisher:
  ...

  lwt notifier:
    topic: sensors/groundfloor/kitchen/status
    message: "Humidity Controller publisher disconnected from broker"
    retain: true
    interval delay: 7
    qos: 2
```

### **Notifier** attributes schema

These attributes provide the configuration parameters to send publisher disconnection notifications to connected subscribers.

<table><thead><tr><th width="200">Attribute</th><th width="220">Description</th><th width="222">Data Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>topic</td><td>Topic to sent status message on to</td><td>String</td><td>true</td></tr><tr><td>message</td><td>Message to send to consumers when publisher no longer exists</td><td><p>String </p><p>Default: "Publisher disconnected from broker"</p></td><td>true</td></tr><tr><td>interval delay</td><td>The Server delays publishing the Client's Will Message until the Will Delay Interval has passed or the Session ends, whichever happens first.</td><td><p>Long</p><p>Default: 5 seconds</p></td><td>false</td></tr><tr><td>retain</td><td>If message is retained</td><td><p>Boolean</p><p>Default: true</p></td><td>false</td></tr><tr><td>qos</td><td>Quality of service</td><td><p>Integer</p><p>Default: 1</p></td><td>false</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.fractalworks.io/joule/components/connectors/sinks/mqtt/last-will-and-testament.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
