Skip to content

Rule Events ​

Actions are the matching rules that connect MQTT messages with external data systems, covering data processing and mapping. MQTT-protocol devices connect to the MQTT service to deliver messages, and actions provide the association for integrating data into external data systems, enabling seamless integration between devices and other business systems.

1. Rule Events ​

The rule engine can handle message publishing, and it can also handle events such as client online/offline and client subscriptions. For events, the event topic follows the FROM clause in the SQL statement.

The following describes all client events.

Connection Established Event ​

Event identifier: $events/client_connected

Triggered when a client successfully connects to the MQTT service.

Available fields

FieldDescription
clientIdclient id
proto_nameprotocol type name
ip_addressclient IP
nodenode IP
portclient port
tsevent trigger time
keepaliveheartbeat interval
clean_startwhether to clear the session
statuswhether online

SQL rule example

sql
select
  *
from
"$events/client_connected"

Example JSON output

json
{
	"proto_name": "MQTT",
	"node": "127.0.0.1",
	"clientId": "S&testD664Q81G8092&41&1",
	"ip_address": "127.0.0.1",
	"port": 52865,
	"ts": 1735455370388,
	"keepalive": 60,
	"clean_start": true,
	"status": true
}

Selected fields example

json
select
  clientId,
  status,
  keepalive
from
"$events/client_connected"

Output data

json
{
	"clientId": "S&testD664Q81G8092&41&1",
	"keepalive": 60,
	"status": true
}

Connection Disconnected Event ​

Event identifier : $events/client_disconnected

Triggered when a client disconnects.

Available fields

FieldDescription
offline_reasonReason the client disconnected:
normal: the client disconnected actively
kicked: kicked out by the server
keepalive_timeout: heartbeat timeout
not_authorized: authentication failed
tcp_closed: the peer closed the network connection
discarded: another client connected with the same clientId
clientIdclient id
statusdevice status
portclient port
ip_addressclient IP
tsevent trigger time
nodenode IP

SQL rule example

sql
select
*
from
"$events/client_disconnected"

Example output

json
{
	"proto_name": "MQTT",
	"node": "127.0.0.1",
	"clientId": "S&testD664Q81G8092&41&1",
	"ip_address": "127.0.0.1",
	"port": 0,
	"ts": 1735456294357,
	"offline_reason": "kicked",
	"status": false
}

Message Publish Event ​

Event identifier: $events/message_publish

Available fields

FieldDescription
proto_nameprotocol name
clientIdclient id
idmessage id
topictopic
peerhostclient IP
payloadMQTT message body
nodenode IP
qosmessage QoS
portclient port
datatypedata type, json/hex/base64/cbor
publish_received_attime the message arrived at the MQTT service
tsevent trigger time

SQL rule example

sql
select
*
from
"$events/message_publish"

Example output

json
{
  "proto_name" : "MQTT",
  "ts" : 1735486854867,
  "clientId" : "S&testD664Q81G8092&41&1",
  "id" : "1873393767773118464",
  "topic" : "/D1832O34Z6M9/property/post",
  "qos" : 0,
  "payload" : [ 123, 13, 10, 32, 32, 34, 109, 115, 103, 34, 58, 32, 34, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 34, 13, 10, 125 ],
  "peerhost" : "127.0.0.1",
  "clientPort" : 65385,
  "node" : "127.0.0.1",
  "publish_received_at" : 1735486854868,
  "datatype" : "json"
}

Client Subscription Succeeded Event ​

Event identifier: $events/session_subscribed

Triggered when a client subscribes successfully.

Available fields

FieldDescription
clientIddestination Client ID of the message
proto_nameprotocol name
peerhostclient IPAddress
topicMQTT topic
qosMQTT event subscribe
eventSUBSCRIBE Properties (5.0 only)
timestampevent trigger time (unit: milliseconds)
nodenode where the event was triggered

SQL rule example

sql
select
*
from
"$events/session_subscribed"

Example output

json
{
    "node": "127.0.0.1",
    "clientId": "860061061621885",
    "peerhost": "127.0.0.1",
    "qos": 0,
    "topic": "/860061061621test/property/post",
    "proto_name": "MQTT",
    "event": "subscribe",
    "timestamp": 1736217855399
}

Client Unsubscription Succeeded Event ​

Event identifier: $events/session_unsubscribed

Triggered when a client unsubscribes successfully.

Available fields

FieldDescription
clientIddestination Client ID of the message
proto_nameprotocol name
peerhostclient IPAddress
topicMQTT topic
tsevent trigger time (unit: milliseconds)
eventSUBSCRIBE Properties (5.0 only)
nodenode where the event was triggered

SQL rule example

sql
select
*
from
"$events/session_unsubscribed"

Example output

json
{
    "node": "127.0.0.1",
    "clientId": "860061061621885",
    "peerhost": "127.0.0.1",
    "topic": "/860061061621test/property/post",
    "proto_name": "MQTT",
    "event": "unSubscribe",
    "ts": 1736217858065
}

Message Acknowledged Event ​

Event identifier: $events/message_acked

Triggered when a message is sent to a client and the client's ack reply is received; only QoS 1 and QoS 2 trigger it.

FieldDescription
idMQTT message ID
from_clientidsource Client ID of the message
from_usernamesource username of the message
clientIddestination Client ID of the message
usernamedestination username of the message
payloadMQTT message body
peerhostclient IPAddress
topicMQTT topic
qosQoS of the MQTT message
nodenode where the event was triggered
timestampevent trigger time (unit: milliseconds)

SQL rule example

sql
SELECT
  from_clientid,
  from_username,
  topic,
  qos,
  node,
  timestamp
FROM
  "$events/message_acked"

Example output

json
{
  "topic": "t/a",
  "timestamp": 1645002965664,
  "qos": 1,
  "node": "127.0.0.1",
  "from_username": "fastbee",
  "from_clientid": "fastbee"
}

Session Keepalive Event ​

Event identifier: $events/session_ping

Triggered when a device heartbeat keepalive occurs.

Available fields

FieldDescription
clientIddestination Client ID of the message
proto_nameprotocol name
portclient port
nodenode where the event was triggered
tsevent trigger time (unit: milliseconds)
ip_addressclient IP

SQL rule example

sql
SELECT
  *
FROM
  "$events/session_ping"

Example output

json
{
    "proto_name": "MQTT",
    "node": "127.0.0.1",
    "clientId": "860061061621885",
    "ip_address": "127.0.0.1",
    "port": 51182,
    "ts": 1736219438405
}

Message Delivered Event ​

Event identifier: $events/client_delivered

Triggered when a message is placed into the underlying socket.

Available fields

FieldDescription
idMQTT message ID
from_clientidsource Client ID of the message
from_usernamesource username of the message
clientIddestination Client ID of the message
usernamedestination username of the message
payloadMQTT message body
peerhostclient IPAddress
topicMQTT topic
qosQoS of the MQTT message
nodenode where the event was triggered
timestampevent trigger time (unit: milliseconds)

SQL rule example

sql
SELECT
  from_clientid,
  from_username,
  topic,
  qos,
  node,
  timestamp
FROM
  "$events/client_delivered"

Example output

json
{
  "topic": "t/a",
  "timestamp": 1645002965664,
  "qos": 1,
  "node": "127.0.0.1",
  "from_username": "fastbee",
  "from_clientid": "fastbee"
}

FastBee | fastbee.cn