rules 命令
rules list | List all rules |
---|---|
rules show <RuleId> | Show a rule |
rules create <name> <hook> <sql> <actions> [-d [<descr>]] | Create a rule |
rules delete <RuleId> | Delete a rule |
rules create
创建一个新的规则:
## 创建一个测试规则,简单打印所有发送到 't/a' 主题的消息内容
$ ./bin/emqx_ctl rules create \
'test1' \
'message.publish' \
'select * from "t/a"' \
'[{"name":"built_in:inspect_action", "params": {"a": 1}}]' \
-d 'Rule for debug'
Rule test1:1556242324634254201 created
Tip
一个规则由系统生成的规则 ID 标识,所以如果用相同的名字重复添加规则,会生成多个 ID 不同的规则。
rules list
列出当前所有的规则:
$ ./bin/emqx_ctl rules list
rule(id='test1:1556242324634254201', name='test1', for='message.publish', rawsql='select * from "t/a"', actions=[{"name":"built_in:inspect_action","params":{"a":1}}], enabled='true', description='Rule for debug')
rules show
查询规则:
## 查询 RuleID 为 'test1:1556242324634254201' 的规则
$ ./bin/emqx_ctl rules show 'test1:1556242324634254201'
rule(id='test1:1556242324634254201', name='test1', for='message.publish', rawsql='select * from "t/a"', actions=[{"name":"built_in:inspect_action","params":{"a":1}}], enabled='true', description='Rule for debug')
rules delete
删除规则:
## 删除 RuleID 为 'test1:1556242324634254201' 的规则
$ ./bin/emqx_ctl rules delete 'test1:1556242324634254201'
ok