Azure Event Grid is a pub-sub message broker that enables you to integrate your solutions at scale using HTTP pull delivery, HTTP push delivery, and MQTT broker capability. The MQTT broker capability leverages standard features from MQTT protocol to enable your clients to communicate in a reliable, secure, and scalable manner. This capability is vital for IoT solutions where efficient communication is essential for seamless operations, driving the digital transformation of organizations across various industries.
Today, I am thrilled to announce the public preview release of the Last Will and Testament (LWT) support in Azure Event Grid's MQTT broker capability, in compliance with the MQTTv3.1.1 and MQTTv5 specifications. LWT enables your MQTT clients to get notified with the abrupt disconnections of other MQTT clients. This powerful feature ensures predictable and reliable flow of communication among MQTT clients during unexpected disconnections, which is valuable for scenarios where real-time communication and coordinated actions are critical.
IoT devices usually operate in environments characterized by unreliable network connectivity, where connections might be sporadic or prone to disruptions due to signal loss, limited power, or other factors. Consequently, MQTT clients might disconnect from the MQTT broker without clear indication whether the disruption was intentional or unexpected. The absence of notifications about the unexpected client disconnections poses a significant challenge across industries, potentially causing service unavailability, increased downtime, and communication failures. In scenarios where multiple MQTT clients collaborate to execute intricate tasks or distribute workload, real-time communication and reliability are critical. These disconnections disrupt the coordination of tasks within the system, leading to inefficiency and performance degradation.
Event Grid’s MQTT broker capability now supports MQTT last will and testament for MQTTv3.1.1 and MQTTv5 clients to address this challenge. When a client connects to the MQTT broker, it can specify a will message, will topic, and the rest of the will properties in the CONNECT packet. If the client disconnects gracefully through the MQTT DISCONNECT packet with reason code 0x00, the will message is discarded. However, if the client ungracefully disconnects, the MQTT broker publishes the will message to all the clients that subscribed to the will topic. Accordingly, the subscribing clients can adapt swiftly to this disconnection by redistributing tasks, reallocating responsibilities, or adjusting their behavior to ensure continued system performance and stability.
In this example, there are actuators that operate based on the data generated from sensors. If the sensors disconnect abruptly, the actuators need to change their behavior or stop since they don’t have real time data from the sensors to act upon. The sensors use MQTT LWT to reliably notify these actuators whenever it disconnects unexpectedly. The clients use the following topics to achieve this capability.
Client |
Role |
Topic/Topic Filter |
sensor1 |
Publisher |
clients/sensor1/status |
sensor2 |
Publisher |
clients/sensor2/status |
actuator1 |
Subscriber |
clients/+/status |
actuator2 |
Subscriber |
clients/+/status |
The following steps show the configuration of the namespace and the sample clients to model this example.
Let’s start by configuring the Event Grid namespace as the MQTT broker that will route these messages among the sensors and actuators. The following steps show the configuration using command-line and Azure CLI. For more information about the Azure portal configuration of the namespace, go to this quickstart.
You can use step CLI to create sample certificates for your clients to authenticate with the namespace.
Use the command to create a namespace
Use the following command to create the client resources. Replace the [Client Thumbprint] in the commands below with the thumbprints that are retrieved from step 3 from the Generate certificates instructions.
Use the following command to create client groups: one for the sensors and one for the actuators.
Create a topic space to configure the MQTT will topics that the sensors use to publish and another one to configure the topic filter to which the actuators subscribe.
Create a permission binding to grant the sensors access to publish on their topic space, and another one to grant the actuators access to subscribe to their topic space.
You can use MQTTX app to model your client samples and the data flow.
Event Grid's MQTT Broker capability now supports Last Will and Testament (LWT) for enhanced reliability among MQTT clients. This feature ensures that MQTT clients are notified in case of unexpected disconnections of other MQTT clients, allowing them to adapt and maintain system stability. Event Grid is committed to ongoing investment in MQTT features to align with MQTT specifications and better support evolving IoT scenarios, ensuring continuous enhancement to meet industry demands.
You can learn more about Azure Event Grid by visiting the links below. If you have questions or feedback, you can contact us at askmqtt@microsoft.com.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.