所有文档

          规则引擎 Rule Engine

          管理接口

          创建规则

          方法 API 说明
          POST /v1/rules 创建规则

          请求参数

          参数名 说明 示例
          endpoint 需要规则引擎处理的mqtt主题对应的服务实例 myendpoint
          from 需要规则引擎处理的mqtt主题 topic/sensor01
          description 规则描述 过滤传感器温度过高消息的规则
          destinations 处理后的消息写往的目的地数组(TSDB, KAFKA,另一个MQTT主题) 见下表
          select 输出哪些字段,SQL语法 *, name, data.temperature
          name 规则名称 sensor_warn
          where 消息过滤条件,SQL语法 data.temperature>90
          dictionary 所绑定的规则字典的uuid 规则字典的uuid

          其中,destinations数组中,每个元素包含如下2个字段:

          参数名 说明 示例
          kind 目的地类型,可能取值:MQTT, KAFKA, TSDB, BOS, MQTT_DYNAMIC, BOS, SMS, FUNCTION, BIN2JSON, RULE, RDS, DICTIONARY MQTT
          value 对应不同的目的地id或者地址 /result/topic

          上表中, kind的取值及其含义:

          取值 解释 示例
          MQTT 物接入主题 /result/topic
          KAFKA 百度消息服务(Kafka)主题 b1f91fbe6fe54d2eaf70ef0025f1c3c2__topic1
          TSDB 时序数据库 iottelemetry3.tsdb-qksrpsyxqndy.tsdb.iot.gz.baidubce.com
          MQTT_DYNAMIC 物接入动态主题选择器 'result/'  deviceid
          BOS 百度对象存储 bos://mybucket/folder1
          SMS 短信接收人uuid
          FUNCTION 函数计算名称[:结果目的地主题] myfunc, 或者myfunc:/result/topic
          BIN2JSON 二进制消息转JSON /result/topic
          RULE 规则引擎 下游规则引擎uuid
          RDS 关系数据库 连接配置uuid
          DICTIONARY 规则字典 规则字典uuid

          返回参数

          参数名 说明 示例
          endpoint 等同传入参数endpoint endpoint1
          state 规则的状态(ENABLED, DISABLED) ENABLED
          from 等同传入参数from mytopic1
          description 等同传入参数description desc1
          accountUuid 当前账号的account uuid 124343-adef-132232
          destinations 类似传入参数destinations,同时加上id, ruleid信息
          select 等同传入参数select name, *
          name 等同传入参数name rulename
          where 等同传入参数where abc > 8 AND name like '%yyj%'
          uuid 系统为规则分配的唯一id 764736473643
          dictionary 绑定的规则字典uuid aa82fb4d-9b1f-4b01-90eb-feaad3afbd59

          请求示例

          {
              "endpoint": "endpoint1",
              "from": "mytopic1",
              "description": "desc1",
              "destinations": [
                  {
                      "value": "dest_topic1",
                      "kind": "MQTT"
                  },
                  {
                      "value": "kafka_topic1",
                      "kind": "KAFKA"
                  },
                  {
                      "value": "TSDB_SERVER_URL",
                      "kind": "TSDB"
                  }
              ],
              "select": "name, *",
              "name": "rulename",
              "where": "abc > 8 AND name like '%yyj%'"
          }

          响应示例

          {
              "endpoint": "endpoint1",
              "state": "ENABLED",
              "from": "mytopic1",
              "description": "desc1",
              "accountUuid": "baidu",
              "destinations": [
                  {
                      "uuid": "6653da99-bf9a-4e35-ba4f-997e000a699f",
                      "ruleUuid": "218cf057-ec2d-415c-8952-cd5cfb641bde",
                      "value": "dest_topic1",
                      "kind": "MQTT"
                  },
                  {
                      "uuid": "e03264b7-4e94-43d1-b5cd-fb0e51f08ebe",
                      "ruleUuid": "218cf057-ec2d-415c-8952-cd5cfb641bde",
                      "value": "kafka_topic1",
                      "kind": "KAFKA"
                  }
              ],
              "select": "name, *",
              "name": "testname3",
              "where": "abc > 8 AND name like '%yyj%'",
              "uuid": "218cf057-ec2d-415c-8952-cd5cfb641bde",
              "dictionary":"aa82fb4d-9b1f-4b01-90eb-feaad3afbd59"
          }

          列显规则

          方法 API 说明
          GET /v1/rules?pageNo=1&pageSize=20 列显规则

          响应示例

          {
          	"totalCount": 1,
          	"result": [{
          		"endpoint": "endpoint1",
          		"state": "ENABLED",
          		"from": "mytopic1",
          		"description": "desc1",
          		"destinations": [{
          				"uuid": "6653da99-bf9a-4e35-ba4f-997e000a699f",
          				"ruleUuid": "218cf057-ec2d-415c-8952-cd5cfb641bde",
          				"value": "dest_topic1",
          				"kind": "MQTT"
          			},
          			{
          				"uuid": "e03264b7-4e94-43d1-b5cd-fb0e51f08ebe",
          				"ruleUuid": "218cf057-ec2d-415c-8952-cd5cfb641bde",
          				"value": "kafka_topic1",
          				"kind": "KAFKA"
          			}
          		],
          		"select": "name, *",
          		"name": "testname3",
          		"createTime": "2016-08-11T06:39:49Z",
          		"where": "abc > 8 AND name like '%yyj%'",
          		"updateTime": "2016-08-11T06:39:49Z",
          		"uuid": "218cf057-ec2d-415c-8952-cd5cfb641bde",
          		"dictionary": "aa82fb4d-9b1f-4b01-90eb-feaad3afbd59"
          	}],
          	"order": "desc",
          	"orderBy": "createtime",
          	"pageSize": 2,
          	"pageNo": 1
          }

          为规则添加目的地

          方法 API 说明
          POST /v1/destinations 为规则添加目的地

          请求参数

          参数名 说明 示例
          ruleUuid 需要添加目的地的规则id 34882348382
          kind 目的地类型,可能取值参考表1 MQTT
          value 不同类型目的地对应的id或者地址 topic/sensor_warn

          请求示例

          {
            "ruleUuid": "9dd573fe-9246-4eaa-bc2f-2ef88615521d",
            "value": "dest_topic1_no3",
            "kind": "MQTT"
          }

          从规则中删除目的地

          方法 API 说明
          DELETE /v1/destinations/{desinnation_id} {desinnation_id}为目的地id

          请求示例

          DELETE http://re.iot.gz.baidubce.com/v1/destinations/c48f65ae-3c18-44d2-952b-4d94d1d16ef4

          读取规则详情

          方法 API 说明
          GET /v1/rules/{rule_id} {rule_id}为规则id

          请求示例

          GET http://re.iot.gz.baidubce.com/v1/rules/43257469-643e-4a1c-81df-8cca28d96dbc

          响应示例

          {
          	"endpoint": "endpoint1",
          	"state": "ENABLED",
          	"from": "mytopic1",
          	"description": "desc1",
          	"destinations": [{
          			"uuid": "6653da99-bf9a-4e35-ba4f-997e000a699f",
          			"ruleUuid": "218cf057-ec2d-415c-8952-cd5cfb641bde",
          			"value": "dest_topic1",
          			"kind": "MQTT"
          		},
          		{
          			"uuid": "e03264b7-4e94-43d1-b5cd-fb0e51f08ebe",
          			"ruleUuid": "218cf057-ec2d-415c-8952-cd5cfb641bde",
          			"value": "kafka_topic1",
          			"kind": "KAFKA"
          		}
          	],
          	"select": "name, *",
          	"name": "testname3",
          	"createTime": "2016-08-11T06:39:49Z",
          	"where": "abc > 8 AND name like '%yyj%'",
          	"updateTime": "2016-08-11T06:39:49Z",
          	"uuid": "218cf057-ec2d-415c-8952-cd5cfb641bde",
          	"dictionary": "aa82fb4d-9b1f-4b01-90eb-feaad3afbd59"
          }

          修改规则

          方法 API 说明
          PUT /v1/rules/{rule_id} {rule_id}为拟修改的规则的id

          请求参数

          参数名 说明 示例
          from 需要规则引擎处理的mqtt主题 topic/sensor01
          description 规则描述 过滤传感器温度过高消息的规则
          select 输出哪些字段,SQL语法 *, name, data.temperature
          where 消息过滤条件,SQL语法 data.temperature>90

          请求示例

          {
            "from": "mytopic1_update",
            "description": "desc1",
            "select": "name, *, abc",
            "where": "abc > 8 AND name like '%yyj% or 1 < 2'"
          }

          响应示例

          {
          	"endpoint": "endpoint1",
          	"state": "ENABLED",
          	"from": "mytopic1_update",
          	"description": "desc1",
          	"destinations": [{
          			"uuid": "6653da99-bf9a-4e35-ba4f-997e000a699f",
          			"ruleUuid": "218cf057-ec2d-415c-8952-cd5cfb641bde",
          			"value": "dest_topic1",
          			"kind": "MQTT"
          		},
          		{
          			"uuid": "e03264b7-4e94-43d1-b5cd-fb0e51f08ebe",
          			"ruleUuid": "218cf057-ec2d-415c-8952-cd5cfb641bde",
          			"value": "kafka_topic1",
          			"kind": "KAFKA"
          		}
          	],
          	"select": "name, *, abc",
          	"name": "testname3",
          	"createTime": "2016-08-11T06:39:49Z",
          	"where": "abc > 8 AND name like '%yyj% or 1 < 2'",
          	"updateTime": "2016-08-11T06:44:13Z",
          	"uuid": "218cf057-ec2d-415c-8952-cd5cfb641bde",
          	"dictionary": "aa82fb4d-9b1f-4b01-90eb-feaad3afbd59"
          }

          批量删除规则

          方法 API 说明
          POST /v1/rules/batch/delete 批量删除规则

          请求参数

          参数名|说明|示例 rules|需要删除的规则id数组|"43257469-643e-4a1c-81df-8cca28d96dbc",
          "2f74da12-a846-4b70-bf3a-7a22e0c56bc0"

          请求示例

          {
          	"rules": [
          		"43257469-643e-4a1c-81df-8cca28d96dbc",
          		"2f74da12-a846-4b70-bf3a-7a22e0c56bc0"
          	]
          }

          禁用一条规则

          方法 API 说明
          PUT /v1/rules/{ruleid}/disable {ruleid}为需要禁用的规则id

          请求示例

          PUT http://re.iot.gz.baidubce.com/v1/rules/218cf057-ec2d-415c-8952-cd5cfb641bde/disable

          启用一条规则

          方法 API 说明
          PUT /v1/rules/{ruleid}/enable {ruleid}为需要启用的规则id

          请求示例

          PUT http://re.iot.gz.baidubce.com/v1/rules/218cf057-ec2d-415c-8952-cd5cfb641bde/enable
          上一篇
          介绍
          下一篇
          数据接口