mmq使用文档
1. 简介
mmq主要实现了事件发布订阅以及环形队列的部分功能,发布组件通过http, grpc, tcp, websocket通道发布事件到mmq,订阅组件通过grpc, tcp, websocket通道从mmq订阅事件。
2. Event
2.1 订阅事件
通过grpc长连接方式, 从mmq订阅事件,主要格式如下:
{
"action":"sub_event",
"event": {
"event":"statistics_realtime_result",
"block":"statistics",
"uid":"STA105313"
}
}
通过tcp长连接方式, 从mmq订阅事件,主要格式如下:
{
"action":"sub_event",
"event": {
"event":"statistics_realtime_result",
"block":"statistics",
"uid":"STA105313"
}
}
通过websocket长连接方式, 从mmq订阅事件,主要格式如下:
// 通过ws://host:port/api建立websocket连接,然后才能订阅事件
{
"action":"sub_event",
"event": {
"event":"statistics_realtime_result",
"block":"statistics",
"uid":"STA105313"
}
}
2.2 取消订阅
取消事件订阅,通过grpc长连接的方式从mmq取消事件订阅,主要格式如下:
{
"action":"unsub_event",
"event": {
"uid":"5a212cbc-c58f-42c9-9509-bd114026388d"
}
}
取消事件订阅,通过tcp长连接的方式从mmq取消事件订阅,主要格式如下:
{
"action":"unsub_event",
"event": {
"uid":"5a212cbc-c58f-42c9-9509-bd114026388d"
}
}
取消事件订阅,通过websocket长连接的方式从mmq取消事件订阅,主要格式如下:
{
"action":"unsub_event",
"event": {
"uid":"5a212cbc-c58f-42c9-9509-bd114026388d"
}
}
3. Action
3.1 事件
3.1.2 发布用户事件
请求参数:
参数名称 | 是否必选 | 数据类型 | 描述 |
---|---|---|---|
action | 是 | string | 指令 |
user_event | 是 | object | 事件 |
… | … | … | 其他参数 |
响应参数:
参数名称 | 数据类型 | 描述 |
---|---|---|
resp | string | 返回指令 |
code | int | 返回码 |
msg | string | 提示消息 |
result:
参数名称 | 数据类型 | 描述 |
---|---|---|
uid | string | 返回终端配置唯一编号 |
请求示例:
curl -H "Content-Type: application/json" -X POST -d '{
"action": "pub_user_event",
"block": "mapping",
"uniqueid": "PUB2530595500002",
"datetime": "2022-05-13 09:50:05",
"user_event": {
"user_event": "update_control",
"id": 80,
"uid": "CTL2414319900001",
"name": "cc1",
"description": "",
"script": [],
"template": [],
"reference": "",
"created": "0001-01-01 00:00:00",
"created_by": 1,
"last_modified": "2022-05-13 09:50:05",
"last_modified_by": 1,
"is_available": 1,
"object_list": null
}
}' http://192.168.88.202:8791/api
响应示例:
{
"resp": "pub_user_event",
"code": 200,
"msg": "成功"
}
3.1.3 取消订阅
请求参数:
参数名称 | 是否必选 | 数据类型 | 描述 |
---|---|---|---|
action | 是 | string | 指令 |
uid | 否 | string | 唯一编号 |
响应参数:
参数名称 | 数据类型 | 描述 |
---|---|---|
resp | string | 返回指令 |
code | int | 返回码 |
msg | string | 提示消息 |
result:
参数名称 | 数据类型 | 描述 |
---|---|---|
uid | string | 返回终端配置唯一编号 |
请求示例:
curl -H "Content-Type: application/json" -X POST -d '{
"action": "unsub_event_register_by_uid",
"uid": "132ed645-6a60-4c63-892f-a15e5c2fef4e"
}' http://192.168.88.202:8791/api
响应示例:
{
"resp": "unsub_event_register_by_uid",
"code": 200,
"msg": "成功"
}
3.1.4 获取事件注册详情(通过事件名)
请求参数:
参数名称 | 是否必选 | 数据类型 | 描述 |
---|---|---|---|
action | 是 | string | 指令 |
event | 是 | string | 事件名称 |
响应参数:
参数名称 | 数据类型 | 描述 |
---|---|---|
resp | string | 返回指令 |
code | int | 返回码 |
msg | string | 提示消息 |
result | object | 返回结果 |
请求示例:
curl -H "Content-Type: application/json" -X POST -d '{
"action": "get_event_register_item",
"event": "statistics_realtime_result"
}' http://192.168.88.202:8791/api
响应示例:
{
"resp": "get_event_register_item",
"code": 200,
"msg": "成功",
"result": [
{
"event": {
"block": "statistics",
"event": "statistics_realtime_result",
"uid": "STA105313"
},
"address": "192.168.88.202:52532",
"uid": "1e3f2807-5cb8-467e-9064-d79ea7e48889"
},
{
"event": {
"block": "statistics",
"event": "statistics_realtime_result",
"uid": "STA105313"
},
"address": "192.168.88.202:52530",
"uid": "a58dfba7-fea5-4fd9-9c03-751c6d463eb9"
},
{
"event": {
"block": "statistics",
"event": "statistics_realtime_result",
"uid": "STA105313"
},
"address": "192.168.88.202:52534",
"uid": "90c374f3-622b-4f28-bbf2-cf90e82956c7"
}
]
}
3.1.5 获取事件注册详情(通过客户端地址)
请求参数:
参数名称 | 是否必选 | 数据类型 | 描述 |
---|---|---|---|
action | 是 | string | 指令 |
addr | 是 | string | 客户端地址 |
响应参数:
参数名称 | 数据类型 | 描述 |
---|---|---|
resp | string | 返回指令 |
code | int | 返回码 |
msg | string | 提示消息 |
result | object | 返回结果 |
请求示例:
curl -H "Content-Type: application/json" -X POST -d '{
"action": "get_event_register_item_by_addr",
"addr": "192.168.88.202:52530"
}' http://192.168.88.202:8791/api
响应示例:
{
"resp": "get_event_register_item_by_addr",
"code": 200,
"msg": "成功",
"result": [
{
"event": {
"block": "statistics",
"event": "statistics_realtime_result",
"uid": "STA105313"
},
"address": "192.168.88.202:52530",
"uid": "a58dfba7-fea5-4fd9-9c03-751c6d463eb9"
}
]
}
3.1.6 获取事件注册详情(通过ip地址)
请求参数:
参数名称 | 是否必选 | 数据类型 | 描述 |
---|---|---|---|
action | 是 | string | 指令 |
ip | 是 | string | 客户端ip地址 |
响应参数:
参数名称 | 数据类型 | 描述 |
---|---|---|
resp | string | 返回指令 |
code | int | 返回码 |
msg | string | 提示消息 |
result | object | 返回结果 |
请求示例:
curl -H "Content-Type: application/json" -X POST -d '{
"action": "get_event_register_item_by_ip",
"ip": "192.168.88.202"
}' http://192.168.88.202:8791/api
响应示例:
{
"resp": "get_event_register_item_by_ip",
"code": 200,
"msg": "成功",
"result": [
{
"event": {
"block": "statistics",
"event": "statistics_realtime_result",
"uid": "STA105313"
},
"address": "192.168.88.202:52532",
"uid": "1e3f2807-5cb8-467e-9064-d79ea7e48889"
},
{
"event": {
"block": "statistics",
"event": "statistics_realtime_result",
"uid": "STA105313"
},
"address": "192.168.88.202:52530",
"uid": "a58dfba7-fea5-4fd9-9c03-751c6d463eb9"
},
{
"event": {
"block": "statistics",
"event": "statistics_realtime_result",
"uid": "STA105313"
},
"address": "192.168.88.202:52534",
"uid": "90c374f3-622b-4f28-bbf2-cf90e82956c7"
}
]
}
3.1.7 获取事件注册详情(通过订阅号)
请求参数:
参数名称 | 是否必选 | 数据类型 | 描述 |
---|---|---|---|
action | 是 | string | 指令 |
uid | 是 | string | 唯一编号 |
响应参数:
参数名称 | 数据类型 | 描述 |
---|---|---|
resp | string | 返回指令 |
code | int | 返回码 |
msg | string | 提示消息 |
result | object | 返回结果 |
请求示例:
curl -H "Content-Type: application/json" -X POST -d '{
"action": "get_event_register_item_by_uid",
"uid": "a58dfba7-fea5-4fd9-9c03-751c6d463eb9"
}' http://192.168.88.202:8791/api
响应示例:
{
"resp": "get_event_register_item_by_uid",
"code": 200,
"msg": "成功",
"result": {
"event": {
"block": "statistics",
"event": "statistics_realtime_result",
"uid": "STA105313"
},
"address": "192.168.88.202:52530",
"uid": "a58dfba7-fea5-4fd9-9c03-751c6d463eb9"
}
}
3.1.8 获取事件注册列表
请求参数:
参数名称 | 是否必选 | 数据类型 | 描述 |
---|---|---|---|
action | 是 | string | 指令 |
响应参数:
参数名称 | 数据类型 | 描述 |
---|---|---|
resp | string | 返回指令 |
code | int | 返回码 |
msg | string | 提示消息 |
result | object | 返回结果 |
请求示例:
curl -H "Content-Type: application/json" -X POST -d '{
"action": "get_event_register_list"
}' http://192.168.88.202:8791/api
响应示例:
{
"resp": "get_event_register_list",
"code": 200,
"msg": "成功",
"result": {
"statistics_realtime_result": [
{
"event": {
"block": "statistics",
"event": "statistics_realtime_result",
"uid": "STA105313"
},
"address": "192.168.88.202:52532",
"uid": "1e3f2807-5cb8-467e-9064-d79ea7e48889"
},
{
"event": {
"block": "statistics",
"event": "statistics_realtime_result",
"uid": "STA105313"
},
"address": "192.168.88.202:52530",
"uid": "a58dfba7-fea5-4fd9-9c03-751c6d463eb9"
},
{
"event": {
"block": "statistics",
"event": "statistics_realtime_result",
"uid": "STA105313"
},
"address": "192.168.88.202:52534",
"uid": "90c374f3-622b-4f28-bbf2-cf90e82956c7"
}
]
}
}
3.1.9 定时事件
mmq服务自身会发布定时事件,即每分钟,每5分钟,每30分钟,每小时都会发布一个事件。Mixiot系统的其他服务可以通过订阅定时事件执行定时任务。
事件名称 | 描述 |
---|---|
one_minute_event | 每分钟事件 |
five_minute_event | 每5分钟事件 |
thirty_minute_event | 每30分钟事件 |
one_hour_event | 每小时事件 |
- 示例
{
"action": "pub_event",
"event": {
"event": "timer_event",
"block": "agent",
"type": "one_minute_event",
"uniqueid": "PUB1344800006032",
"datetime": "2021-04-21 18:08:08"
}
}
文档更新时间: 2025-02-18 12:35 作者:技术支持