用途说明
基于 Topic 进行通信时,您可以使用规则引擎对 Topic 中的数据进行处理,然后转发到腾讯云其它服务或用户的业务后台服务,进行数据采集、计算、存储等服务。
创建规则
1. 登录 物联网开发平台控制台,在实例列表中,找到对应的实例,单击实例卡片。
2. 在左侧导航栏选择数据流转 > 规则引擎。
3. 进入规则引擎页面,单击新建规则,填入规则名称后,单击保存。
规则名称:支持英文、数字、下划线的组合,最多不超过32个字符。(名称新建后无法修改,请谨慎填写。)
规则描述:0 - 256个字的描述,可修改。

4. 创建成功后,即可自动进入规则详情页面,您可以编辑数据筛选和添加行为操作。

筛选数据
通过选择设备、topic 类型、设置需选择提取的内容字段和条件,生成提取数据的 SQL 语句。
名词解释 | 描述 | 示例 | |
字段 | 设备上报 JSON 数据支持通过字段提取数据内容,多个字段用逗号隔开。如果需全部字段转发,填入' * '号。设备上报是非 JSON 数据,只能填入' * '号进行全部内容转发。字段定义如下: 字段中仅支持' * '、','、'.'、空格、字母和数字,不为空,最多不超过300个字符。 字段表示的是 JSON 中的键值 Key。若数据格式为非 JSON 数据时,不可使用字段筛选,可使用' * '将所有数据进行转发。 上报的 JSON 数据格式,可以是嵌套的 JSON。例如:{"device_status":{"switch":"on"}},可以通过 device_status.switch 来获取到 switch 的值。 暂不支持子 SQL 和 JSON 数组。 | | 取所有数据字段:'*'; 取物模型中的 timestamp1 字段:'params.timestamp1,' |
Topic | 可指定产品应用下的全部设备或其中一台设备进行订阅,同时也支持订阅不同 Topic 类型。具体类型如下: 自定义 OTA消息上报 云存消息上行 用户与设备绑定关系变更通知 物模型自定义上报 物模型属性上报 物模型事件上报 物模型行为上报 设备状态变化通知 网关子设备拓扑关系消息上报 | | 物模型属性上报:$thing/up/property/D22711XVM1/+ |
条件 | | | |
当前 SQL | 该字段系统会根据字段、Topic、条件自动生成 SQL 语句,无需手动填写 | | SELECT params.timestamp1, FROM '$thing/up/property/D22711XVM/+' |
运算表达
及说明:运算符号 | 说明 | 示例 |
= | 相等 | color = 'red' |
<> | 不等于 | color <> 'red' |
AND | 逻辑与 | color = 'red' AND siren = 'on' |
OR | 逻辑或 | color = 'red' OR siren = 'on' |
( ) | 括号代表一个整体 | color = 'red' AND (siren = 'on' OR siren ='isTest') |
+ | 算术加法 | age = 4 + 5 |
- | 算术减 | age = 5 - 4 |
/ | 除 | age = 20 / 4 |
* | 乘 | age = 5 * 4 |
% | 取余数 | age = 0 % 6 |
< | 小于 | 5 < 6 |
<= | 小于或等于 | 5 <= 6 |
> | 大于 | 6 > 5 |
>= | 大于或等于 | 6 >= 5 |
行为操作
用于配置接收数据的目标,支持以下行为类型:
转发错误行为操作
通过配置与行为操作不同的行为类型,当行为操作进行3次重试转发都失败后,会向错误行为操作进行1次转发,确保设备数据不丢失。
规则引擎行日志错误码
content | result | errcode | errcode释义 |
Send message to RuleEngine, topic:{} | FAIL, system error | Msg_Send_To_Rule_System_Err | 转发失败,系统错误。 |
MQ:forward CMQ, type:{}, CMQ{queue: {}, region: {}} | FAIL, queue name is not existed, or deleted | MQ_Queue_NotExist_Or_Deleted | 转发失败,队列不存在,或者队列已经被删除了。 |
| FAIL, exceed maximum message size | MQ_Exceed_Max_Msg_Size | 转发失败,存在至少一条消息达到了最大消息大小限制。 |
| FAIL, reach maximum retention number of message | MQ_Reach_Max_Retention_Num | 转发失败,达到队列的最大消息堆积数。 |
| FAIL, unexpected error: {} | MQ_Forward_CMQ_Unexpected_Err | 转发失败,腾讯云接口公共错误。 |
| FAIL, system error | MQ_Forward_CMQ_System_Err | 转发失败,系统错误。 |
MQ forward CKafka, type:{}, Ckafka{instance:{}, topic: {}, region: {}} | FAIL, unexpected error: {} | MQ_Forward_Kafka_Unexpected_Err | 转发失败,Kafka 错误信息。 |
| FAIL, system error | MQ_Forward_Kafka_System_Err | 转发失败,系统错误。 |
RuleEngine republish message, source topic:{}, destination topic: {} | FAIL, no such field({}) in payload | Payload_No_Field | 转发失败,payload 没有对应的字段。 |
| FAIL, system error | Rule_Repub_System_Err | 转发失败,系统错误。 |
RuleEngine forward third-party server,topic:{}, url:{} | FAIL, url server timeout | Forward_Third_Not_Responding | 转发失败,第三方服务器无响应。 |
| FAIL, system error | Forward_Third_System_Err | 转发失败,系统错误。 |
RuleEngine forward CKafka, topic:{}, Ckafka.instance:{}, topic: {}, region: {},retry times:{}" | FAIL,unexpected error: {} | Rule_Forward_Kafka_Unexpected_Err | 转发失败,Kafka 错误信息。 |
RuleEngine forward CMQ Topic, IOT topic:{}, CMQ.topic:{}, region:{} | FAIL,system error:{} | MQ_Queue_NotExist_Or_Deleted | 转发失败,队列不存在,或者已经被删除了。 |
| | MQ_Exceed_Max_Msg_Size | 转发失败,消息超过最大值限制。 |
| | MQ_Reach_Max_Retention_Num | 转发失败,达到最大保持数目。 |
| | Rule_Forward_CMQ_Topic_No_Subscription | 转发失败,本主题没有订阅者。 |
| | Rule_Forward_CMQ_Topic_Unexpected_Err | 转发失败,未知错误。 |
RuleEngine forward CMQ Queue, IOT topic:{}, CMQ.topic:{}, region:{} | FAIL,system error:{} | MQ_Queue_NotExist_Or_Deleted | 转发失败,队列不存在,或者已经被删除了。 |
| | MQ_Exceed_Max_Msg_Size | 转发失败,消息超过最大值限制。 |
| | MQ_Reach_Max_Retention_Num | 转发失败,达到最大保持数目。 |
| | Rule_Forward_CMQ_Topic_No_Subscription | 转发失败,本主题没有订阅者。 |
| | Rule_Forward_CMQ_Topic_Unexpected_Err | 转发失败,未知错误。 |
RuleEngine forward CTSDB. topic:{}, CTSDB.instanceid:{}, region:{}, metric:{} | FAIL,system error:{} | Rule_Forward_Ctsdb_System_Err | 转发失败,系统错误。 |
RuleEngine forward Mongo, topic:{}, Mongo.instanceid:{}, database:{}, collection:{} | FAIL,system error:{} | Rule_Forward_MongoDB_System_Err | 转发失败,系统错误。 |
RuleEngine forward TCB Func,get role error topic:{}, TCB.envID:{}, functionName:{} | FAIL,system error:{} | Rule_Forward_TCB_Func_System_err | 转发失败,系统错误。 |
RuleEngine forward Mysql.IOT topic:{}. info:{} | FAIL,system error:{} | Rule_Forward_Mysql_System_Err | 转发失败,系统错误。 |
RuleEngine forward TDMQ.IOT topic:{}. info:{} | FAIL,system error:{} | Rule_Forward_TDMQ_System_Err | 转发失败,系统错误。 |
Process sql: {} | FAIL,unexpected error:{} | Rule_Process_SQL_Err | 执行失败。 |
Payload is not JSON fmt | FAIL | Payload_Not_JSON | 消息负载不是 JSON 格式。 |