代码拉取完成,页面将自动刷新
Baetyl-Rule 可以实现 Baetyl 框架端侧的消息流转,在 Baetyl-Broker(端侧消息中心)、函数服务、Iot Hub(云端 Mqtt Broker) 进行消息交换。
支持以下的消息流转方式:
其中 Baetyl 支持 Python、Node、Sql 等多种运行时,可以配置相关的脚本函数对消息进行过滤、处理、转换以及丰富等,具体可以参考 Baetyl-Function 模块。
Baetyl-Rule 的全量配置文件如下,并对配置字段做了相应解释:
clients: # 消息节点,可以从消息节点订阅消息,也可以发送至消息节点
- name: iothub # 名称
kind: mqtt # mqtt 类型
address: 'ssl://u7isgiz.mqtt.iot.bj.baidubce.com:1884' # 地址
username: client.example.org # 用户名
ca: ../example/var/lib/baetyl/testcert/ca.pem # 连接节点的 CA
key: ../example/var/lib/baetyl/testcert/client.key # 连接节点的私钥
cert: ../example/var/lib/baetyl/testcert/client.pem # 连接节点的公钥
insecureSkipVerify: true # 是否跳过服务端证书校验
- name: http-client # 名称
kind: http # http类型(仅可配置为target)
address: 'http://127.0.0.1:8554' # http服务地址,如果是https,请配置证书,否则默认使用系统证书
ca: ../example/var/lib/baetyl/testcert/ca.pem # 连接节点的 CA
key: ../example/var/lib/baetyl/testcert/client.key # 连接节点的私钥
cert: ../example/var/lib/baetyl/testcert/client.pem # 连接节点的公钥
insecureSkipVerify: true # 是否跳过服务端证书校验
- name: http-server # 名称
kind: http-server # http-server类型(仅可配置为source)
port: 8090 # http server服务端口,下面的tls可选,不配置时,默认为http服务
ca: ../example/var/lib/baetyl/testcert/ca.pem # 服务器的 CA
key: ../example/var/lib/baetyl/testcert/client.key # 服务器的私钥
cert: ../example/var/lib/baetyl/testcert/client.pem # 服务器的公钥
insecureSkipVerify: true # 是否跳过服务端证书校验
rules: # 消息规则
- name: rule1 # 规则名称,必须保持唯一
source: # 消息源
topic: broker/topic1 # 消息主题
qos: 1 # 消息质量
target: # 消息目的地
client: iothub # 消息节点,如果不设置,默认为 baetyl-broker
topic: iothub/topic2 # 消息主题
qos: 0 # 消息质量
function: # 处理函数
name: node85 # 函数名称
- name: rule2 # 规则名称,必须保持唯一
source: # 消息源
topic: broker/topic5 # 消息主题
qos: 0 # 消息质量
target: # 消息目的地
client: http-client # 与clients中配置的http服务名称一致
path: /nodes/test # http访问路径
method: PUT # http消息类型,支持GET/POST/PUT/DELETE
- name: rule3 # 规则名称,必须保持唯一
source: # 消息源
client: http-server # 指定为http-server的消息源
target: # 消息目的地
client: http-client # 与clients中配置的http服务名称一致
path: /nodes/test # http访问路径
method: PUT # http消息类型,支持GET/POST/PUT/DELETE
说明:
http://{ip}:{port}/rules/{ruleName}
来触发调用下面示例定义了三条规则:
py-demo1/func1
的输入,将函数计算结果输出至broker/topic2
py-demo1/func2
的输入,将函数计算结果通过http POST请求发送至http://127.0.0.1:8554/rule/result
clients:
- name: http-server
kind: http
address: 'http://127.0.0.1:8554'
rules:
- name: rule1
source:
topic: broker/topic1
target:
topic: broker/topic2
function:
name: py-demo1/func1
- name: rule2
source:
topic: broker/topic3
target:
client: http-server
path: /rule/result
method: POST
function:
name: py-demo1/func2
logger:
level: debug
encoding: console
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。