Message Queue for MQTT Message Queue for MQTT (MQTT) supports synchronous event notification and synchronous event notification to obtain the online status of the MQTT client. This topic describes the basic principles, scenarios, differences, and implementation of these two modes.

How it works

Message Queue for MQTT The MQTT broker provides the following methods to obtain the online status of the client:
  • Synchronous query

    This method is relatively simple. You can call an HTTP/HTTPS API through an open endpoint to query the real-time status of a specific MQTT client. This method is suitable for determining the status of one or more MQTT clients.

  • Asynchronous online /offline event notification

    This method uses notification messages. When an MQTT client goes online or offline, the MQTT broker online /offline notification rules pushes an online /offline message to other Alibaba cloud products. Service applications are generally deployed on Alibaba Cloud ECS instances. Service applications can subscribe to this message to retrieve the online /offline events of all clients.

    Note Currently, you can use only one of the following Alibaba Cloud products to: Message Queue for Apache RocketMQ.

    This method perceives the client status asynchronously and detects the online and offline events rather than the online status of the client. Therefore, cloud-based applications need to analyze the client status based on the timeline of a series of events.


The two methods of obtaining the online status of an MQTT client are applicable to the following scenarios:

  • Synchronous query
    • The subsequent operation logic needs to be determined based on whether the client is online or not during the main service process.
    • You need to determine whether the specified client is online during O&M.
  • Asynchronous event notification
    • The MQTT broker (short for AliwareMQ for IoT broker) needs to trigger some predefined actions when an MQTT client goes online or offline.

Differences between synchronous queries and asynchronous event notifications

The differences between both methods are as follows:
  • A synchronous query is to query the real-time status of a client. Theoretically, it is more accurate than an asynchronous notification.
  • Asynchronous online/offline notification messages are based on message decoupling, so status determination is more complex and more likely to be incorrect. However, this method can analyze the running status traces of multiple clients based on events. Although asynchronous notification has some complexity and incorrect judgment, it is more suitable for large-scale client status statistics.

How it works