规则引擎(rule engine) 命令

rules 命令

命令描述
rules listList all rules
rules show <RuleId>Show a rule
rules create <sql> <actions> [-d [<descr>]]Create a rule
rules delete <RuleId>Delete a rule

rules create

创建一个新的规则。参数:

  • <sql>: 规则 SQL
  • <actions>: JSON 格式的动作列表
  • -d <descr>: 可选,规则描述信息

使用举例:

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

上例创建了一个 ID 为 rule:9a6a725d 的规则,动作列表里只有一个动作:动作名为 inspect,动作的参数是 {"a": 1}

rules list

列出当前所有的规则:

  1. $ ./bin/emqx_ctl rules list
  2. rule(id='rule:9a6a725d', for='['t/a']', rawsql='select * from "t/a"', actions=[{"metrics":...,"name":"inspect","params":...}], metrics=..., enabled='true', description='Rule for debug')

rules show

查询规则:

  1. ## 查询 RuleID 为 'rule:9a6a725d' 的规则
  2. $ ./bin/emqx_ctl rules show 'rule:9a6a725d'
  3. rule(id='rule:9a6a725d', for='['t/a']', rawsql='select * from "t/a"', actions=[{"metrics":...,"name":"inspect","params":...}], metrics=..., enabled='true', description='Rule for debug')

rules delete

删除规则:

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

rule-actions 命令

命令描述
rule-actions listList actions
rule-actions show <ActionId>Show a rule action

TIP

动作可以由 EMQ X 内置(称为系统内置动作),或者由 EMQ X 插件编写,但不能通过 CLI/API 添加或删除。

rule-actions show

查询动作:

  1. ## 查询名为 'inspect' 的动作
  2. $ ./bin/emqx_ctl rule-actions show 'inspect'
  3. action(name='inspect', app='emqx_rule_engine', types=[], title ='Inspect (debug)', description='Inspect the details of action params for debug purpose')

rule-actions list

列出符合条件的动作:

  1. ## 列出当前所有的动作
  2. $ ./bin/emqx_ctl rule-actions list
  3. action(name='data_to_rabbit', app='emqx_bridge_rabbit', types=[bridge_rabbit], title ='Data bridge to RabbitMQ', description='Store Data to Kafka')
  4. action(name='data_to_timescaledb', app='emqx_backend_pgsql', types=[timescaledb], title ='Data to TimescaleDB', description='Store data to TimescaleDB')
  5. ...

resources 命令

命令描述
resources create <type> [-c [<config>]] [-d [<descr>]]Create a resource
resources list [-t <ResourceType>]List resources
resources show <ResourceId>Show a resource
resources delete <ResourceId>Delete a resource

resources create

创建一个新的资源,参数:

  • type: 资源类型
  • -c config: JSON 格式的配置
  • -d descr: 可选,资源的描述
  1. $ ./bin/emqx_ctl resources create 'web_hook' -c '{"url": "http://host-name/chats"}' -d 'forward msgs to host-name/chats'
  2. Resource resource:a7a38187 created

resources list

列出当前所有的资源:

  1. $ ./bin/emqx_ctl resources list
  2. resource(id='resource:a7a38187', type='web_hook', config=#{<<"url">> => <<"http://host-name/chats">>}, status=#{is_alive => false}, description='forward msgs to host-name/chats')

列出当前某个类型的资源:

  1. $ ./bin/emqx_ctl resources list --type='web_hook'
  2. resource(id='resource:a7a38187', type='web_hook', config=#{<<"url">> => <<"http://host-name/chats">>}, status=#{is_alive => false}, description='forward msgs to host-name/chats')

resources show

查询资源:

  1. $ ./bin/emqx_ctl resources show 'resource:a7a38187'
  2. resource(id='resource:a7a38187', type='web_hook', config=#{<<"url">> => <<"http://host-name/chats">>}, status=#{is_alive => false}, description='forward msgs to host-name/chats')

resources delete

删除资源:

  1. $ ./bin/emqx_ctl resources delete 'resource:a7a38187'
  2. ok

resource-types 命令

命令描述
resource-types listList all resource-types
resource-types show <Type>Show a resource-type

TIP

资源类型可以由 EMQ X 内置(称为系统内置资源类型),或者由 EMQ X 插件编写,但不能通过 CLI/API 添加或删除。

resource-types list

列出当前所有的资源类型:

  1. ./bin/emqx_ctl resource-types list
  2. resource_type(name='backend_mongo_rs', provider='emqx_backend_mongo', title ='MongoDB Replica Set Mode', description='MongoDB Replica Set Mode')
  3. resource_type(name='backend_cassa', provider='emqx_backend_cassa', title ='Cassandra', description='Cassandra Database')
  4. ...

resource-types show

查询资源类型:

  1. $ ./bin/emqx_ctl resource-types show backend_mysql
  2. resource_type(name='backend_mysql', provider='emqx_backend_mysql', title ='MySQL', description='MySQL Database')