rules 命令

rules listList 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

创建一个新的规则:

  1. ## 创建一个测试规则,简单打印所有发送到 't/a' 主题的消息内容
  2. $ ./bin/emqx_ctl rules create \
  3. 'test1' \
  4. 'message.publish' \
  5. 'select * from "t/a"' \
  6. '[{"name":"built_in:inspect_action", "params": {"a": 1}}]' \
  7. -d 'Rule for debug'
  8. Rule test1:1556242324634254201 created

Tip

一个规则由系统生成的规则 ID 标识,所以如果用相同的名字重复添加规则,会生成多个 ID 不同的规则。

rules list

列出当前所有的规则:

  1. $ ./bin/emqx_ctl rules list
  2. 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

查询规则:

  1. ## 查询 RuleID 为 'test1:1556242324634254201' 的规则
  2. $ ./bin/emqx_ctl rules show 'test1:1556242324634254201'
  3. 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

删除规则:

  1. ## 删除 RuleID 为 'test1:1556242324634254201' 的规则
  2. $ ./bin/emqx_ctl rules delete 'test1:1556242324634254201'
  3. ok