Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions en_US/data-integration/rule-sql-events-and-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,15 @@ Refer to the table below for fields that can be selected from the received MQTT

This event topic can be used to trigger a rule when a client is disconnected.

For example, you can use the statement below to extract data from the `"$events/client_disconnected"` event topic that includes the following data fields: client ID, username, disconnect reason, disconnect time, and EMQX node where the event is triggered.
For example, you can use the statement below to extract data from the `"$events/client_disconnected"` event topic that includes the following data fields: client ID, username, disconnect reason, connection start time, disconnect time, and EMQX node where the event is triggered.

Example:
```sql
SELECT
clientid,
username,
reason,
connected_at,
disconnected_at,
node
FROM
Expand All @@ -351,20 +352,20 @@ Output:
"username": "u_emqx",
"reason": "normal",
"node": "[email protected]",
"connected_at": 1645003578036,
"disconnected_at": 1645003578536,
"clientid": "c_emqx"
}
```



| Field | Explanation |
| :---------------- | :----------------------------------------------------------- |
| `reason` | Disconnect reasons<br/><br/>`normal`: The client is intentionally disconnected <br/><br/>`kicked`: EMQX has forcibly removed the client through REST API<br/><br/>`keepalive_timeout`: The specified keepalive time period expired.<br/><br/>`not_authorized`: Authorization failed.<br/><br/>`tcp_closed`: The peer has closed network connection.<br/><br/>`discarded`: Another client ( with `clean_start` set to `true`) connected with the same ClientID, causing the previous connection to be dropped.<br/><br/>`takenover`: Another client ( with `clean_start` set to `false`) connected with the same ClientID, taking over the previous connection..<br/><br/>`internal_error`: An error has occurred due to an improperly formatted message or other unknown issues. |
| `clientid` | Client ID |
| `username` | Client username |
| `peername` | IP Address and Port number |
| `sockname` | IP Address and Port number listened by EMQX |
| `connected_at` | Client connection start time (unit: ms). This timestamp represents when the current session was established and helps identify which connection session the disconnect event belongs to.<br />It ensures that delayed disconnect events do not overwrite newer connection states. |
| `disconnected_at` | Client disconnection completion time (unit: ms) |
| `disconn_props` | DISCONNECT Properties (MQTT 5.0 clients only) |
| `timestamp` | Event trigger time (unit: ms) |
Expand Down
3 changes: 3 additions & 0 deletions zh_CN/data-integration/rule-sql-events-and-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ FROM
| username | 消息目的用户名 |
| peername | 客户端的 IPAddress 和 Port |
| sockname | emqx 监听的 IPAddress 和 Port |
| connected_at | 客户端连接开始时间(单位:毫秒)。该时间戳表示当前会话建立的时间,有助于识别断开事件所属的连接会话。<br />此字段可确保延迟的断开事件不会覆盖较新的连接状态。 |
| disconnected\_at | 客户端连接断开时间 (单位:毫秒) |
| disconn\_props | DISCONNECT Properties (仅适用于 MQTT 5.0) |
| timestamp | 事件触发时间 (单位:毫秒) |
Expand All @@ -360,6 +361,7 @@ SELECT
clientid,
username,
reason,
connected_at,
disconnected_at,
node
FROM
Expand All @@ -373,6 +375,7 @@ FROM
"username": "u_emqx",
"reason": "normal",
"node": "[email protected]",
"connected_at": 1645003578036,
"disconnected_at": 1645003578536,
"clientid": "c_emqx"
}
Expand Down
Loading