by Ranjith Kumar DSM | Mar 14, 2017 | MQTT | 0 comments
Every IoT network is a collaborative working of edge devices. All devices should work in unison to make the environment conducive for the humans. This article helps you make the best use of the MQTT Last WILL Messages.
Last Will is a way of peer to peer monitoring between MQTT clients that operate in a more understanding way. Before we go into the real time use cases, it is better to understand the spec better.
Last Will is a message stored in the MQTT broker specific to particular clients. The Last Will message is a normal MQTT Message that has a will topic, will message , MQTT QoS and retain flag. These messages will be sent to the clients who have subscribed to those WILL topics by the broker when the particular client disconnects ungracefully.
A more detailed explanation of how you have to send the connect packet is available in our Developing MQTT Clients documentation.
The WILL Messages will be published by the broker to all the interested subscribers when the particular client gets disconnected from the broker ungracefully. When the client disconnects using a proper disconnect message, the WILL will not be published. The client needs to notify the interesting parties on going down by publishing proper message by itself.
All mission critical devices needs a back up. Let us take an example of a Database server in an online application. It is one of the core component that needs to run always for the complete service to be useful.
These applications will have masters , slaves and standby servers which needs to be deployed when any of the servers fails. The master server should add a WILL on Connection. The slave will be subscribing to the particular WILL. The WILL should be configured specific to each cluster of the master slave. In this scenario, the broker should be configured to publish the WILL for the graceful as well as ungraceful disconnection of the Master. When the master disconnects, the slave receives the master unavailable message and the necessary scripts can be triggered for the slave to become the master. The standby servers will become slave and now will subscribe to the WILL of the new master.
This is one scenario of automated take over. Such scenarios exist in all industries like Medical, all kind of Manufacturing industries. We can also use the WILL Message triggers for monitoring the devices and their uptime from a central server.
You can avoid a lot of unwanted monitoring messages to each devices by making the right use of MQTT Last WILL Messages.
Please take a moment to fill this form