Open In App

Fundamental Features of MQTT | Set 3

Prerequisites –

Last Will and Testament :
In MQTT, publisher client publishes messages on specific topic to Broker. The broker then publishes these messages to clients subscribed to that topic. If the publisher/subscriber client wants to end connection with broker, it sends DISCONNECT message. In this way, communication can be disconnected gracefully.



But there are several scenarios in which client might get disconnected abruptly. In such case, client ends communication with broker without sending DISCONNECT message. In such scenarios, other clients will not be informed about failure and hence they will keep waiting for messages from disconnected client.

A client could get disconnected abruptly due to any of following reasons –



To solve such problem, concept of last will messages is used. Using this feature, client provides predefined will message when it first gets connected to broker. This message is stored by the broker.

LWT message and LWT topic :


Figure – Last Will and Testament


Example –


Figure – Mosquitto Illustration of Last Will and Testament


In the above illustration, will topic is “sensor/status” and will message is “offline”. Once client disconnects abruptly, socket error is displayed on mosquito broker terminal. Hence broker then sends will message “offline” to client subscribed to topic “sensor/status”.

Mosquitto Commands :

Article Tags :