---
schema_version: "1"
id: e36af88ffbc88e14b727026daf11e15426b0859fa94a925975e45cdcee24fc5e
title: Configure the Last Will and Testament Messages for MQTT Connector
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mqtt3-connector/latest/mqtt3-connector-lwt-message.md
canonical_url: https://docs.mulesoft.com/mqtt3-connector/latest/mqtt3-connector-lwt-message
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 95882adcb5b722627c9505a6ee15fc384a574758e35a4dc188d0402801c89a56
description: MuleSoft Documentation Site
release: "1.1"
latest: true
---
---
product: MQTT Connector
version: 1.1
is-latest-version: true
---

# Configure the Last Will and Testament Messages for MQTT Connector

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

In this example, you set a Last Will and Testament (LWT) message for Anypoint Connector for MQTT
(MQTT Connector) to ensure that a message is sent to all of the subscribers of a specific LWT topic
if the client disconnects temporarily or permanently from the broker. The LWT message is sent when
the connection to the broker is established.

Configure the LWT message in the configuration element and specify whether or not you want the
broker to retain that message. If an MQTT message is set for retention, the broker stores the last
message marked as retained that arrived at a specific topic. If no listeners are subscribed to a
matching topic at the time the message is sent, the broker stores the message until a listener
connects to that topic. Then, the broker delivers the listener to the last message retained for that
topic.

1.  In Studio, navigate to the **Global Elements** tab.

2.  Click **Create**.

3.  In the filter box, type `mqtt` and select **MQTT3 Config**.

4.  Click **OK**.

5.  In **MQTT3 Config** > **Connection**, select **MQTT3 Form Connection**.

6.  For **Client id generator**, select **Client id random suffix generator**.

7.  Set the following fields:

    - **Client ID**: `smart-bentley-123`

    - **Username**: `usertest`

    - **Password**: `passtest`

    - **URL**: `tcp://127.0.0.1:1883`

8.  Click **LWT**.

9.  Set the following fields:

    - **Topic**: `LWT`

    - **Body**: `Testing body message`

    - **Is retained**: **True**.

10. Click **OK**.

![MQTT Config window with Last Will and Testament configuration window selected](/mulesoft/current/en-us/mqtt3-connector/latest/_images/mqtt3-lwt-configuration.png)

In the **Configuration XML** editor, the `<mqtt3:last-will-and-testament>` configuration looks like
this:

```xml
<mqtt3:config name="MQTT_LWT_Config">
    <mqtt3:connection username="usertest" password="passtest" url="tcp://127.0.0.1:1883">
        <mqtt3:client-id-generator >
            <mqtt3:client-id-random-suffix-generator clientId="smart-bentley-123" />
        </mqtt3:client-id-generator>
        <mqtt3:last-will-and-testament topic="LWT" isRetained="true" >
            <mqtt3:body ><![CDATA[Testing body message]]></mqtt3:body>
        </mqtt3:last-will-and-testament>
    </mqtt3:connection>
</mqtt3:config>
```

## See Also

- [MQTT Connector Examples](https://docs.mulesoft.com/mqtt3-connector/latest/mqtt3-connector-examples)

- [Salesforce Help](https://help.salesforce.com)
