Working with last will and testament in Java

Now, we will take advantage of the last will and testament feature. We will create the main class named Main that uses the asynchronous API of the Paho Java Client, the previously coded SecurityHelper class to establish an encrypted connection with an MQTT server, and the SensorsManager class to process the received messages with commands. The code will configure a message to be sent as the last will when the connection is lost. In addition, the Main class will call the loop method for a SensorsManager instance to publish messages with data retrieved from the sensors when they are turned on with the appropriate commands.

We will split the code for the Main class into many code snippets to make it easier ...

Get MQTT Essentials - A Lightweight IoT Protocol now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.