Our final MQTT feature for exploration is known as a Will. A client (publisher or subscriber) can register a special Will message with the broker so that if the client dies and disconnects from the broker abruptly (for example, it loses its network connection or its batteries go flat), the broker on the clients' behalf will send out the Will message notifying subscribers of the device's demise.
Wills are just a message and topic combination similar to what we have been using previously.Â
Let's see Wills in action, and for this, we're going to need three Terminals:
- Open a Terminal and start a subscriber with the following command:
# Terminal #1 (Subscriber with Will)
$ mosquitto_sub -h localhost -t 'pyiot' --will-topic 'pyiot' --will-payload 'Good Bye' --will-qos 2 --will-retain
The new options are as follows:
-
- --will-payload: This is the Will message.
- --will-topic: This is the topic the Will...