This is the design guide of message routing rule engine for the EMQX Broker.
A rule is:
when
Match <conditions> | <predicates>
then
Select <data> and Take <action>;
or:
rule "Rule Name"
when
rule match
select
para1 = val1
para2 = val2
then
action(#{para2 => val1, #para2 => val2})
|-----------------|
P ---->| Message Routing |----> S
|-----------------|
| /|\
\|/ |
|-----------------|
| Rule Engine |
|-----------------|
| |
Backends Services Bridges
Event | Message -> Rules -> Actions -> Resources
P -> |--------------------| |---------------------------------------|
| Messages (Routing) | -> | Rules (Select Data, Match Conditions) |
S <- |--------------------| |---------------------------------------|
|---------| |-----------| |-------------------------------|
->| Actions | -> | Resources | -> | (Backends, Bridges, WebHooks) |
|---------| |-----------| |-------------------------------|
A rule consists of a SELECT statement, a topic filter, and a rule action
Rules consist of the following:
The operations on a rule:
Actions consist of the following:
Define a rule action in ADT:
action :: Application -> Resource -> Params -> IO ()
A rule action:
Module:function(Args)
backend:mysql:localhost:port:db
backend:redis:localhost:
webhook:url
bridge:kafka:
bridge:rabbit:localhost
The properties and behaviors of resources is defined by resource types. A resoure type is provided(contributed) by a plugin.
Provider of resource type is a EMQX Plugin.
Supervisor
|
\|/
Action ----> Proxy(Batch|Write) ----> Connection -----> ExternalResource
| /|\
|------------------Fetch----------------|
Rules API Actions API Resources API
rules list
rules show <RuleId>
rule-actions list
rule-actions show <ActionId>
resources list
resources show <ResourceId>
resource_templates list
resource_templates show <ResourceType>