Mixiot事件消息

1. 文档说明

本文档为Mixiot事件说明文档,提供应用第三方开发时参考与使用!

2. 修订记录

日期 文档版本 描述 修订
2021-06-15 v1.0 创建文档 Mixlinker
2021-09-01 v1.1 补充事件说明 Mixlinker

3. 事件概述

Mixiot是一个事件驱动的实时系统,当发生某个事件时将发布一个消息,称为事件消息。事件消息是系统预先定义的,支持模块间相互通信。

特别地,Mixiot定义了一个用户事件,提供第三方自定义发布事件消息。

3.1. 事件消息流程

事件代理示意图

Mixiot事件遵循统一规范,每一个服务既可以是事件消息的生产者,也可以是事件消息的消费者;其中,Agent是事件代理服务,负责事件消息转发:

  1. 事件消费者向Agent订阅事件消息;
  2. 事件生产者向Agent发布事件消息;
  3. Agent将事件消息转发给订阅的应用服务(即订阅事件消息的事件消费者)。


其中, 事件消费者订阅事件时会发送订阅参数,只有事件生产者发布的数据与事件订阅者订阅的参数匹配时Agent才会转发(不是无差别转发)。

3.2. 事件消息格式

事件消息是JSON格式数据,包括event、block、uniqueid、datetime等4个统一参数(必须),以及自定义参数(非必须)。

  • 事件参数
参数名称 数据类型 描述
event String 事件名称
block String 服务标识
uniqueid String 事件消息编号
datetime Datetime 消息产生时间
... 自定义 自定义参数
  • 事件示例
{
    "event":"timer_event",
    "block":"agent",
    "uniqueid":"PUB1344800006032",
    "datetime":"2021-03-04 17:13:48",
    "type":"one_minute_event"
}

上面示例为一个系统定时事件,自定义参数type表示该事件是一个每分钟事件。

4. 事件列表

4.1. 定时事件

定时事件是mixiot定时发出的事件消息,支持外部定时任务执行。

4.2. 每分钟事件

  • 描述:每分钟发布一个事件消息
{
    "event":"timer_event",
    "block":"agent",
    "uniqueid":"PUB1344800006032",
    "datetime":"2021-03-04 17:13:48",
    "type":"one_minute_event"
}

4.3. 每5分钟事件

  • 描述:每5分钟发布一个事件消息
{
    "event":"timer_event",
    "block":"agent",
    "uniqueid":"PUB1344800006032",
    "datetime":"2021-03-04 17:13:48",
    "type":"five_minute_event"
}

4.4. 每30分钟事件

  • 描述:每30分钟发布一个事件消息
{
    "event":"timer_event",
    "block":"agent",
    "uniqueid":"PUB1344800006032",
    "datetime":"2021-03-04 17:13:48",
    "type":"thirty_minute_event"
}

4.5. 每小时事件

  • 描述:每小时发布一个事件消息
{
    "event":"timer_event",
    "block":"agent",
    "uniqueid":"PUB1344800006032",
    "datetime":"2021-03-04 17:13:48",
    "type":"one_hour_event"
}

4.6. 系统事件

Mixiot系统事件包括机器发生事件(终端上下线、设备报警),业务操作事件(用户添加、删除对象),以及应用服务事件(维保到期提醒、统计结果输出)等各类事件。

4.7. 终端上线事件

  • 描述:终端(比如适配器)成功连接Gards(MQTT服务)时将发布一个终端上线事件
{
    "event": "terminal_online",
    "block": "mapping",
    "uniqueid": "PUB1503841600007",
    "datetime": "2021-05-10 11:48:38.416995644",
    "uid": "AX2021063000101",
    "online": 1
}

4.8. 终端离线事件

  • 描述:终端(比如适配器)断开连接Gards(MQTT服务)时将发布一个终端下线事件
{
    "event": "terminal_offline",
    "block": "mapping",
    "uniqueid": "PUB1502615200001",
    "datetime": "2021-05-10 14:31:26.152819794",
    "uid": "AX2021063000101",
    "online": 0
}

4.9. 马赛克更新事件

  • 描述:马赛克拼接时发布该事件;马赛克拼接在映射表中定义,具体配置详见映射表配置规范。
{
    "event": "recv_fv",
    "block": "mosaic",
    "uniqueid": "PUB1323431200006",
    "datetime": "2021-03-12 16:15:34",
    "object_id": "OBJ1315925700001",
    "data": {"S01": "1", "S02": "2"}
}

4.10. 对象条件事件

  • 描述:对象条件事件是对象通过逻辑条件定义的开机、关机、故障、报警等事件,马赛克拼接时如果满足条件则发布该事件;与马赛克更新事件一样,条件事件在映射表中定义
{
    "event": "trigger_event",
    "block": "mosaic",
    "uniqueid": "PUB1323431200006",
    "datetime": "2021-03-12 16:15:34",
    "object_id": "OBJ1315925700001",
    "terminal_id": "AX20210902001010",
    "code": "1001",
    "label_en": "High Temperature",
    "label_local": "设备温度过高",
    "value": {
        "S01": 300,
        "S02": 78
    }
}

4.11. 创建终端配置事件

  • 描述:当成功创建终端配置时则发布该事件
{
    "event": "create_terminal_config",
    "block": "mapping",
    "uniqueid": "PUB1323431200006",
    "datetime": "2021-03-12 16:15:34",
    "uid": "TCF1323431200006",
    "name": "config1",
    "description": "config number 1",
    "hardware": "arm",
    "mcu_file": "/var/image/default",
    "mcu_version": "v1.0.0",
    "remosu_file": "var/image/default",
    "remosu_version": "v1.0.0",
    "lua_file": "var/image/default",
    "lua_version": "v1.0.0",
    "terminal_script": "{\"alt\": 1}",
    "config_script": "{\"alt\": 1}",
    "reference": "参考号123",
    "created": "2020/9/28 14:44:1",
    "created_by": 1,
    "last_modified": "2020/9/28 14:44:1",
    "last_modified_by": 1,
    "is_available": 1
}

4.12. 更新终端配置事件

  • 描述:当成功更新终端配置时则发布该事件
{
    "event": "update_terminal_config",
    "block": "mapping",
    "uniqueid": "PUB1323431200006",
    "datetime": "2021-03-12 16:15:34",
    "uid": "TCF1323431200006",
    "name": "config2",
    "description": "config number 2",
    "hardware": "arm",
    "mcu_file": "/var/image/default",
    "mcu_version": "v1.0.0",
    "remosu_file": "var/image/default",
    "remosu_version": "v1.0.0",
    "lua_file": "var/image/default",
    "lua_version": "v1.0.0",
    "terminal_script": "{\"alt\": 1}",
    "config_script": "{\"alt\": 1}",
    "reference": "参考号123",
    "created": "2020/9/28 14:44:1",
    "created_by": 1,
    "last_modified": "2020/9/28 14:44:1",
    "last_modified_by": 1,
    "is_available": 1
}

4.13. 删除终端配置事件

  • 描述:当成功删除终端配置时则发布该事件
{
    "event": "delete_terminal_config",
    "block": "mapping",
    "uniqueid": "PUB1323431200006",
    "datetime": "2021-03-12 16:15:34",
    "uid": "TCF1323431200006"
}

4.14. 创建终端事件

  • 描述:当成功创建终端时则发布该事件
{
    "event": "create_terminal",
    "block": "mapping",
    "uniqueid": "PUB1323431200006",
    "datetime": "2021-03-12 16:15:34",
    "uid": "AX2021063000101",
    "name": "AX101适配器",
    "description": "terminal1",
    "type": "Aprus-X",
    "maker": "智物联",
    "config_id": "TCF1212994600001",
    "mode": "pwd",
    "username": "test",
    "pin": "test",
    "access": "all",
    "topic": "all",
    "server": "192.168.0.132",
    "session_expiry": 120,
    "keep_alive": 30,
    "encryption": 0,
    "dixie": 1,
    "rsa_privatekey": "12345678",
    "reference": "参考号123",
    "created_by": 1,
    "last_modified_by": 1,
    "is_available": 1
}

4.15. 更新终端事件

  • 描述:当成功更新终端时则发布该事件
{
    "event": "update_terminal",
    "block": "mapping",
    "uniqueid": "PUB1323431200006",
    "datetime": "2021-03-12 16:15:34",
    "uid": "AX2021063000101",
    "name": "AX101适配器",
    "description": "terminal7",
    "type": "Aprus-X",
    "maker": "智物联",
    "config_id": "TCF1212994600001",
    "is_route": 1,
    "mode": "auto",
    "username": "test",
    "pin": "test",
    "access": "all",
    "topic": "all",
    "server": "192.168.0.132",
    "session_expiry": 120,
    "keep_alive": 30,
    "encryption": 0,
    "dixie": 1,
    "rsa_privatekey": "12345678",
    "reference": "参考号123",
    "created_by": 1,
    "last_modified_by": 1,
    "is_available": 1
}

4.16. 删除终端事件

  • 描述:当成功删除终端时则发布该事件
{
    "event": "delete_terminal",
    "block": "mapping",
    "uniqueid": "PUB1323431200006",
    "datetime": "2021-03-12 16:15:34",
    "uid": "AX2021063000101"
}

4.17. 创建映射表事件

  • 描述:当成功创建映射表时则发布该事件
{
    "event": "create_mapping",
    "block": "mapping",
    "uniqueid": "PUB1323431200006",
    "datetime": "2021-03-12 16:15:34",
    "uid": "MAP1323431200006",
    "name": "mapping1",
    "description": "mapping number 1",
    "script": "[[\"v1\", \"\", \"STA变量-相对适配器\", \"STA\", \"$AprusID-1.L1_3_7_2\", \"\", \"\"], [\"v2\", \"\", \"STA变量-相对适配器\", \"STA\", \"$AprusID-1.L1_3_7_2\", \"v1+10\", \"\"], [\"v3\", \"\", \"STA变量-固定适配器\", \"STA\", \"AX20210229000249.L1_3_7_2\", \"v2+10\", \"\"], [\"v4\", \"\", \"离线推送\", \"STA\", \"$CollectID-1.Tem\", \"Tem+20\", \"\"], [\"v5\", \"\", \"离线推送\", \"STA\", \"COL12236500002.Tem\", \"Tem+5\", \"\"], [\"v6\", \"\", \"函数计算\", \"STA\", \"$AprusID-1.L1_3_7_2\", \"min(v1, v2)\", \"\"], [\"v7\", \"\", \"比较运算\", \"STA\", \"$AprusID-1.L1_3_7_2\", \"v1>v2?v1:v2\", \"\"], [\"1001\", \"start event\", \"开始事件\", \"EVNT\", \"$AprusID-1.L1_3_7_2\", \"\", \"v1==0\"], [\"1002\", \"stop event\", \"停止事件\", \"EVNT\", \"$AprusID-1.L1_3_7_2\", \"\", \"v1==1\"]]",
    "addition": "{\"id\":1}",
    "reference": "参考号123",
    "created_by": 1,
    "last_modified_by": 1,
    "is_available": 1
}

4.18. 更新映射表事件

  • 描述:当成功更新映射表时则发布该事件
{
    "event": "update_mapping",
    "block": "mapping",
    "uniqueid": "PUB1323431200006",
    "datetime": "2021-03-12 16:15:34",
    "uid": "MAP1323431200006",
    "name": "mapping1",
    "description": "mapping number 1",
    "script": "[[\"v1\", \"\", \"STA变量-相对适配器\", \"STA\", \"$AprusID-1.L1_3_7_2\", \"\", \"\"], [\"v2\", \"\", \"STA变量-相对适配器\", \"STA\", \"$AprusID-1.L1_3_7_2\", \"v1+10\", \"\"], [\"v3\", \"\", \"STA变量-固定适配器\", \"STA\", \"AX20210229000249.L1_3_7_2\", \"v2+10\", \"\"], [\"v4\", \"\", \"离线推送\", \"STA\", \"$CollectID-1.Tem\", \"Tem+20\", \"\"], [\"v5\", \"\", \"离线推送\", \"STA\", \"COL12236500002.Tem\", \"Tem+5\", \"\"], [\"v6\", \"\", \"函数计算\", \"STA\", \"$AprusID-1.L1_3_7_2\", \"min(v1, v2)\", \"\"], [\"v7\", \"\", \"比较运算\", \"STA\", \"$AprusID-1.L1_3_7_2\", \"v1>v2?v1:v2\", \"\"], [\"1001\", \"start event\", \"开始事件\", \"EVNT\", \"$AprusID-1.L1_3_7_2\", \"\", \"v1==0\"], [\"1002\", \"stop event\", \"停止事件\", \"EVNT\", \"$AprusID-1.L1_3_7_2\", \"\", \"v1==1\"]]",
    "addition": "{\"id\":1}",
    "reference": "参考号123",
    "created_by": 1,
    "last_modified_by": 1,
    "is_available": 1
}

4.19. 删除映射表事件

  • 描述:当成功删除映射表时则发布该事件
{
    "event": "delete_mapping",
    "block": "mapping",
    "uniqueid": "PUB1323431200006",
    "datetime": "2021-03-12 16:15:34",
    "uid": "MAP1323431200006",
}

4.20. 创建对象事件

  • 描述:当成功创建对象时则发布该事件
{
    "event": "create_object",
    "block": "mapping",
    "uniqueid": "PUB1321207800001",
    "datetime": "2021-03-12 16:15:34",
    "uid": "OBJ1321207800001",
    "name": "object1",
    "description": "temperature object",
    "image": "/var/image/default.png",
    "province": "广东省",
    "city": "深圳市",
    "mapping_id": "MAP1212994600001",
    "control_id": "CTL1212994600001",
    "terminal_list": ["test","test1"],
    "object_list": [],
    "collect_list": ["test","test1"],
    "tag": ["test","test1"],
    "model": "model1",
    "serial_no": "1234566778999999",
    "gis": "深圳南山区",
    "secret": "1234567887654321",
    "control": "1234567887654321",
    "addition": "{\"id\":1}",
    "reference": "123456",
    "created_by": 1,
    "last_modified_by": 1,
    "is_available": 1
}

4.21. 更新对象事件

  • 描述:当成功更新对象时则发布该事件
{
    "event": "update_object",
    "block": "mapping",
    "uniqueid": "PUB1321207800001",
    "datetime": "2021-03-12 16:15:34",
    "uid": "OBJ1321207800001",
    "name": "object1",
    "description": "temperature object",
    "image": "/var/image/default.png",
    "province": "广东省",
    "city": "深圳市",
    "mapping_id": "MAP1212994600001",
    "control_id": "CTL1212994600001",
    "terminal_list": ["test","test1"],
    "object_list": [],
    "collect_list": ["test","test1"],
    "tag": ["test","test1"],
    "model": "model1",
    "serial_no": "1234566778999999",
    "gis": "深圳南山区",
    "secret": "1234567887654321",
    "control": "1234567887654321",
    "addition": "{\"id\":1}",
    "reference": "123456",
    "created_by": 1,
    "last_modified_by": 1,
    "is_available": 1
}

4.22. 删除对象事件

  • 描述:当成功删除对象时则发布该事件
{
    "event": "delete_object",
    "block": "mapping",
    "uniqueid": "PUB1321207800001",
    "datetime": "2021-03-12 16:15:34",
    "uid": "OBJ1321207800001"
}

4.23. 创建控制码事件

  • 描述:当成功创建控制码时则发布该事件
{
    "event": "create_control",
    "block": "mapping",
    "uniqueid": "PUB1321207800001",
    "datetime": "2021-03-12 16:15:34",
    "uid": "CTL1321207800001",
    "name": "control1",
    "description": "control number 1",
    "script": "[[\"S001\",\"\",\"模拟变量1\",\"OBJ\",\"$AprusID-1.L1_3_8\",\"\"],[\"S002\",\"\",\"模拟变量2\",\"OBJ\",\"$AprusID-1.L1_3_9\",\"\"],[\"AXUpgrade\",\"Aprus Upgrade\",\"适配器升级\",\"APR\",\"$AprusID-1\",\"LUA\"]]",
    "template": "{\"id\":1}",
    "reference": "参考号123",
    "created_by": 1,
    "last_modified_by": 1,
    "is_available": 1
}

4.24. 更新控制码事件

  • 描述:当成功更新控制码时则发布该事件
{
    "event": "update_control",
    "block": "mapping",
    "uniqueid": "PUB1321207800001",
    "datetime": "2021-03-12 16:15:34",
    "uid": "CTL1321207800001",
    "name": "control2",
    "description": "control number 2",
    "script": "[[\"S001\",\"\",\"模拟变量1\",\"OBJ\",\"$AprusID-1.L1_3_8\",\"\"],[\"S002\",\"\",\"模拟变量2\",\"OBJ\",\"$AprusID-1.L1_3_9\",\"\"],[\"AXUpgrade\",\"Aprus Upgrade\",\"适配器升级\",\"APR\",\"$AprusID-1\",\"LUA\"]]",
    "template": "{\"id\":1}",
    "reference": "参考号123",
    "created_by": 1,
    "last_modified_by": 1,
    "is_available": 1
}

4.25. 删除控制码事件

  • 描述:当成功删除控制码时则发布该事件
{
    "event": "delete_control",
    "block": "mapping",
    "uniqueid": "PUB1321207800001",
    "datetime": "2021-03-12 16:15:34",
    "uid": "CTL1321207800001",
}

4.26. 维保任务到期事件

  • 描述:维保任务到期时发布该事件,其中维保任务在定时维保应用中配置
{
    "event": "mixtimer_event",
    "block": "mixtimer",
    "uniqueid": "MIXTIMER1305938200004",
    "datetime": "2006-01-02 15:04:05",
    "uid": "MIXTIMER1305938200004", // timer 的 uid
    "object_id": "OBJ1001", // timer 对应的 object_id
    "name": "检查设备运行", // 维保名称
    "closing_time": "2006-01-02 15:04:05", // 预计到期时间
    "countdown": "1h" // 当前剩余时间
}

4.27. 离线数据值更新事件

  • 描述:离线采集的数据更新时发布该事件,其中离线采集在离线采集应用中配置
{
    "event": "collect_add_value_event",
    "block": "collect",
    "uniqueid": "COLEVT1",
    "datetime": "2006-01-02 15:04:05",
    "collect_id": " COLVAL1303892400001",
    "object_id": "OBJ1243475500001",
    "name": "test",
    "value": {
        "Tem": 32,
        "num2": 64
    }
}

4.28. 统计生成结果事件

  • 描述:统计生成结果时发布该事件,其中统计在统计计算应用中配置
{
    "event":"statistics_result",
    "block":"statistics",
    "uniqueid":"PUB1395846800005",
    "datetime":"2021-04-06 16:10:00",
    "uid":"STATISTICS1395846800005",
    "object_id":"1001",
    "type":"statistics",
    "data":"17.8"
}

4.29. 计算生成结果事件

  • 描述:计算生成结果时发布该事件,其中计算在统计计算应用中配置
{
    "event":"statistics_result",
    "block":"statistics",
    "uniqueid":"PUB1395846800005",
    "datetime":"2021-04-06 16:10:00",
    "uid":"CALCULATE1794188254349",
    "object_id":"1001",
    "type":"calculate",
    "data":"17.8"
}

4.30. 统计实时结果更新事件

  • 描述:统计实时结果更新时发布该事件,其中统计在统计计算应用中配置(与统计生成结果事件相比,统计实时结果是中间结果,中间结果会根据马赛克拼接实时更新)
{
    "event": "statistics_realtime_result",
    "block": "statistics",
    "uniqueid": "PUB1750194800024",
    "datetime": "2021-07-15 18:00:01.948192559",
    "uid": "STATISTICS1715215500001",
    "object_id": "OBJ1683604400009",
    "data": {
            "time_pair": {
            "start": "2021-07-15 18:00:00.5300004",
            "end": "2021-07-15 18:00:01.532693656"
        },
        "data": 2
    }
}

4.31. 历程开始事件

  • 描述:历程开始时发布该事件,其中历程在Retainer历程服务中配置(历程开始事件中不含关闭时间和持续时间,因为还未关闭)
{
    "event": "retainer_open",
    "block": "retainer",
    "uniqueid": "RE1692708800002",
    "datetime": "2021-06-29 17:18:27.088332982",
    "uid": "RETAINER1692708300001",
    "code": "a2b",
    "label_local": "a2b_cn",
    "label_en": "a2b_en",
    "category":"EVENT",
    "object_id": "OBJ1684490200006",
    "template_id": "RETAINER1641792400002",
    "retained": "1",
    "opened_at": "2021-06-29 17:18:27.083170192",
    "value":{
        "S01":1
    }
}

4.32. 历程结束事件

  • 描述:历程结束时发布该事件,其中历程在Retainer历程服务中配置
{
    "event": "retainer_close",
    "block": "retainer",
    "uniqueid": "RE1693508400003",
    "datetime": "2021-06-29 17:18:35.084547288",
    "uid": "RETAINER1692708300001",
    "code": "a2b",
    "label_local": "a2b_cn",
    "label_en": "a2b_en",
    "category":"EVENT",
    "object_id": "OBJ1684490200006",
    "retained": "0",
    "template_id": "RETAINER1641792400002",
    "opened_at": "2021-06-29 17:18:27.083170192",
    "close_at": "2021-06-29 17:18:35.079986923",
    "elapsed": "7.996816749s",
    "value":{
        "S01":1
    },
    "statis_result": 100
}

4.33. 历程转发条件事件

  • 描述:当历程收到对象条件事件且历程还未结束时则转发对象条件事件,其中转发的对象条件事件增加了历程相关信息
{
    "event": "retainer_event",
    "block": "retainer",
    "uniqueid": "PUB1713794014267",
    "datetime": "2021-07-21 17:53:37.938143671",
    "code": "1001",
    "label_en": "start event",
    "label_local": "开始事件",
    "object_id": "OBJ1684490200006",
    "terminal_id": "DX202103300001",
    "value": {
        "collect_volt": 50
    },
    "uid": "RETAINER1692708300001",
    "retainer_code": "A01",
    "template_id": "RETAINER1641792400002",
    "category":"EVENT"
}

4.34. 用户事件

用户事件即用户自定义事件,第三方应用服务可以通过API接口发布用户事件;用户事件与其他事件相比,同时多了user_event固定参数(用户事件名称);其中,事件消息其他参数可以自定义。

  • 用户事件示例
{
    "event":"user_event",
    "block":"agent",
    "uniqueid":"PUB1344800006032",
    "datetime":"2021-03-04 17:13:48",
    "user_event": "mix_event",
    "source": "app"
}

5. 事件订阅发布

Mixiot事件的发布订阅通过Mixiot接口实现。其中,订阅支持事件回调和订阅连接两种方式(更多接口的使用方式详见Mixiot接口说明文档)。

5.1. 事件订阅

5.1.1 建立事件订阅连接

  • 描述

订阅连接是一种长连接方式。此方式下,发起订阅的一方必须按照格式描述的要求发送Json数据到Agent;在与Agent建立连接之后,需要与Agent保持连接。此后,Agent会将匹配到的消息发通过这个连接发送给订阅方,一旦订阅方断开连接,则Agent会根据这个断开的连接自动取消订阅。

特别地,事件订阅连接目前只支持Websocket(TCP)方式。

  • 格式
参数名称 是否必选 数据类型 数据约束 描述
action String sub_agent_event 方法名
actionid String 活动标识
event Json 指明agent类型是event
+ event String
+ ... 自定义 自定义参数
  • 示例
{
    "action": "sub_agent_event",
    "actionid": "abc",
    "event": {
        "event": "timer_event",
        "type": "one_minute_event"
    }
}
  • 返回
{
    "resp": "sub_agent_event",
    "actionid": "abc",
    "code": 200,
    "msg": "成功",
    "result": {
        "uid": "EVNT1463595100003"
    }
}

其中,订阅返回的实际数据如下(详见事件列表):

{
    "event": "timer_event",
    "block": "agent",
    "uniqueid": "PUB1132700015867",
    "datetime": "2021-11-03 10:02:27.000764431",
    "type": "one_minute_event"
}

5.1.2 创建事件回调任务

  • 描述

事件回调是一种短连接方式。此方式下,发起订阅的一方必须按照格式描述的要求发送Json数据到Agent;Agent不关心当前的连接是否存在,当Agent匹配到消息之后,会根据格式描述的回调地址和回调参数和消息进行回调。

特别地,事件回调任务方式支持 HTTP,Websocket(TCP)等方式。

  • 格式
参数名称 是否必选 数据类型 数据约束 描述
action String 异步方式add_agent_task 方法名
actionid String 活动标识
task Json 指明agent类型是task
+ event String
+ ... 自定义参数 自定义参数
+ callback_addr String 事件回调地址
++ callback_params Json
+++ action String
+++ method String http \ websocket \ tcp 回调方式

订阅者必须确保 callback_addr是一个可以访问的地址,并且callback_addr的方式和 callback_params.method 必须一致

  • 示例
{
    "action": "add_agent_task",
    "actionid": "abc",
    "task": {
        "event": "timer_event",
        "type": "one_minute_event",
        "callback_addr": "http://192.168.1.208:1235/mixlog/api",
        "callback_params": {
            "action": "get_action_list",
            "actionid": "",
            "method": "http"
        }
    }
}
  • 返回
{
    "resp": "add_agent_task",
    "actionid": "abc",
    "code": 200,
    "msg": "成功",
    "result": {
        "uid": "TASK1460995400162"
    }
}

其中,订阅返回的实际数据如下(详见事件列表):

{
    "action": "get_action_list",
    "actionid": "",
    "event": "timer_event",
    "block": "agent",
    "uniqueid": "PUB1130000601077",
    "datetime": "2021-11-03 10:37:00.006936585",
    "type": "one_minute_event"
}

5.2. 取消订阅

5.2.1 取消事件订阅连接

  • 描述

取消订阅的时候,必须通过UID来取消。特别的,在此订阅模式下,并不一定需要显式的取消订阅,当订阅者断开连接的时候,Agent会强制自动取消订阅。

  • 格式
参数名称 是否必选 数据类型 数据约束 描述
action String unsub_agent_event 方法名
actionid String 活动标识
uid String
  • 示例

{
    "action":"unsub_agent_event",
    "uid":"EVNT1343675700011"
}
  • 返回

{
    "resp": "unsub_agent_event",
    "code": 200,
    "msg": "成功"
}

5.2.2 取消事件回调任务

  • 描述

取消订阅的时候,必须通过UID来取消。特别的,在此订阅模式下,一定需要显式的取消订阅。

  • 格式
参数名称 是否必选 数据类型 数据约束 描述
action String cancel_agent_task 方法名
actionid String 活动标识
uid String
  • 示例

{
    "action":"cancel_agent_task",
    "uid":"SUB1262842000001"
}
  • 返回

{
    "resp": "cancel_agent_task",
    "code": 200,
    "msg": "成功"
}

5.3. 发布用户事件

  • 描述

用户事件通过API接口发布自定义事件消息。

  • 格式
参数名称 是否必选 数据类型 数据约束 描述
action String generate_user_event 方法名
actionid String 活动标识
user_event String 事件名称
... 自定义 自定义参数
  • 示例
{
    "action": "generate_user_event",
    "user_event": "mix_event",
    "source": "app"
}
  • 返回
{
    "resp": "generate_user_event",
    "code": 200,
    "msg": "成功",
    "result": {
        "event":"user_event",
        "block":"agent",
        "uniqueid":"PUB1344800006032",
        "datetime":"2021-03-04 17:13:48",
        "user_event": "mix_event",
        "source": "app"
    }
}

其中,实际发布的用户事件如下:

{
    "event":"user_event",
    "block":"agent",
    "uniqueid":"PUB1344800006032",
    "datetime":"2021-03-04 17:13:48",
    "user_event": "mix_event",
    "source": "app"
}
© Mixlinker all right reserved,powered by Gitbook文件修订时间: 2022-03-10 10:36:38

results matching ""

    No results matching ""

    results matching ""

      No results matching ""