Inclusive
The inclusive component routes to all matched branches. Unlike switch, which stops at the first matched case, inclusive evaluates all configured cases and forwards the message to each relation whose expression evaluates to true. If none matches, it routes to the Default relation. If expression evaluation fails, it routes to Failure.
# Configuration
| Field | Type | Description | Default |
|---|---|---|---|
| cases | List of Case | List of case expressions | None |
Case:
| Field | Type | Description | Default |
|---|---|---|---|
| case | string | Conditional expression | None |
| then | string | Relation name | None |
Expressions use the expr (opens new window) engine and support variables:
id– message IDts– message timestamp (ms)data– original message contentmsg– message body, access asmsg.fieldwhendataTypeis JSONmetadata– message metadata, e.g.,metadata.customerNametype– message typedataType– data type
Examples:
msg.temperature > 50msg.temperature > 50 && metadata.customerName == 'rulego'upper(metadata.customerName[:4]) == 'GO'replace(toJSON(msg),'name','productName')msg.humidity >= 80 || msg.temperature >= 30
See more syntax and functions: expr language definition (opens new window)
# Relation Type
- Case.then: When a case evaluates to
true, the message is routed to the relation named bythen(multiple branches may be routed simultaneously) - Default: When no case matches, the message is routed to
Default - Failure: When expression evaluation fails, the message is routed to
Failure
# Execution Result
This component is purely for routing; it does not modify msg, metadata, or msgType. For each matched case, the message is forwarded once. If none matches, it forwards to Default.
Implementation reference: in d:\github\rulego\components\common\inclusive_node.go:66, the component iterates all cases, collects matched relations, and calls TellNext with multiple relation types; otherwise it routes to Default.
# Comparison with Switch
switch(conditional branch): evaluates cases in order and stops at the first match, routing to a single branch.inclusive(inclusive branch): evaluates all cases and routes to all matched branches; if none matches, routes toDefault.- Error handling: identical; on evaluation error, routes to
Failure.
# Configuration Example
{
"ruleChain": {
"id": "inc-01",
"name": "Inclusive Branch Demo",
"debugMode": true,
"root": true
},
"metadata": {
"endpoints": [],
"nodes": [
{
"id": "node_inclusive",
"additionalInfo": { "description": "", "layoutX": 480, "layoutY": 280 },
"type": "inclusive",
"name": "inclusive",
"debugMode": false,
"configuration": {
"cases": [
{ "case": "msg.temperature>=20 && msg.temperature<=50", "then": "Case1" },
{ "case": "msg.temperature>50", "then": "Case2" }
]
}
},
{ "id": "node_case1", "additionalInfo": { "description": "", "layoutX": 840, "layoutY": 160 }, "type": "jsTransform", "name": "case1", "debugMode": false, "configuration": { "jsScript": "msg=msg||{}\nmsg.match='Case1'\nreturn {'msg':msg,'metadata':metadata,'msgType':msgType};" } },
{ "id": "node_case2", "additionalInfo": { "description": "", "layoutX": 840, "layoutY": 280 }, "type": "jsTransform", "name": "case2", "debugMode": false, "configuration": { "jsScript": "msg=msg||{}\nmsg.match='Case2'\nreturn {'msg':msg,'metadata':metadata,'msgType':msgType};" } },
{ "id": "node_default", "additionalInfo": { "description": "", "layoutX": 840, "layoutY": 380 }, "type": "jsTransform", "name": "default", "debugMode": false, "configuration": { "jsScript": "msg=msg||{}\nmsg.match='Default'\nreturn {'msg':msg,'metadata':metadata,'msgType':msgType};" } }
],
"connections": [
{ "fromId": "node_inclusive", "toId": "node_case1", "type": "Case1" },
{ "fromId": "node_inclusive", "toId": "node_case2", "type": "Case2" },
{ "fromId": "node_inclusive", "toId": "node_default", "type": "Default" }
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34