Connection Details

There are a other capabilities that MQTT provides that allows one to tune the protocol a little.

Last will and testament

The biggest of these features is the Last-Will-And-Testament (LWAT) message. LWAT messages are publish messages that are packaged up with the connect packet and held by the server for the duration of the connection. If the client loses the connection with the broker (say by missing a ping or closing the connection without sending a disconnect packet) then the LWAT will be sent by the broker on the topic specified in the connect packet.

A common use case would be for clients to have their LWAT message publish on a topic dedicated to these messages. A subscriber on that topic could then restart the clients or forward the reports to a different service.

Note that the LWAT is completely optional.


Another feature is the retain flag. If the retain flag is set, then the message will be retained for that topic and sent to any new subscribers. Sending a message with the retain flag overwrites the currently the currently retained message a particular topic.