Online and Offline notification

EMQX online and offline system message notification function automatically sends a system topic message when the client connection is successful or the client is disconnected, and EMQX turns on the online and offline notification module by default.

Create module

The online and offline notification module is started by default and can be started and stopped through the dashboard page.

Open EMQX DashboardPresence - 图1 (opens new window), click the “Modules” tab on the left:

image-20200927213049265

Select the online and offline notification module

image-20200927213049265

There is no need to configure any parameters for the online and offline notification. After you click Add directly, the module is added.

image-20200927213049265

Online and offline message notification format

$SYS Subject prefix: $SYS/brokers/${node}/clients/

| Topic | Description | | ———————————— | ———————————— ———————— | | ${clientid}/connected | Online event. When any client goes online, EMQX will publish a message on that topic | | ${clientid}/disconnected | Offline event. When any client goes offline, EMQX will publish a message on that topic |

The Payload of the connected event message is parsed into JSON format as follows:

  1. {
  2. "username": "foo",
  3. "ts": 1625572213873,
  4. "sockport": 1883,
  5. "proto_ver": 4,
  6. "proto_name": "MQTT",
  7. "keepalive": 60,
  8. "ipaddress": "127.0.0.1",
  9. "expiry_interval": 0,
  10. "connected_at": 1625572213873,
  11. "connack": 0,
  12. "clientid": "emqtt-8348fe27a87976ad4db3",
  13. "clean_start": true
  14. }

The Payload of the disconnected event message is parsed into JSON format as follows:

  1. {
  2. "username": "foo",
  3. "ts": 1625572213873,
  4. "sockport": 1883,
  5. "reason": "tcp_closed",
  6. "proto_ver": 4,
  7. "proto_name": "MQTT",
  8. "ipaddress": "127.0.0.1",
  9. "disconnected_at": 1625572213873,
  10. "clientid": "emqtt-8348fe27a87976ad4db3"
  11. }