jsFilter
jsFilter
component: script filter. You can use JavaScript script to filter msg, metadata, msgType. The script should return the route to True or False chain.
JavaScript script supports ECMAScript 5.1(+) syntax specification and some ES6 specifications, such as: async/await/Promise/let. It allows calling Go custom functions in the script, please refer to udf .
# Configuration
Field | Type | Description | Default value |
---|---|---|---|
jsScript | string | js script | None |
jsScript
: You can filter msg, metadata, msgType. This field is the following function body contentfunction Filter(msg, metadata, msgType) { ${jsScript} }
1
2
3- msg: Message content, if dataType=JSON, type is:
jsonObject
, you can usemsg.temperature
to operate. If dataType is other types, the field type is:string
- metadata: Message metadata, type:
jsonObject
- msgType: Message type
- Function return value type:
boolean
, determines the connection relationship with the next node (Relation Type
)
- msg: Message content, if dataType=JSON, type is:
Note
jsScript
script must have a return value, return true/false;
Script execution timeout configuration reference: config.ScriptMaxExecutionTime
# Relation Type
- True: Send the message to the
True
chain - False: Send the message to the
False
chain - Failure: Execution failed, send the message to the
Failure
chain
# Execution result
This component will not change the content of msg
, metadata
and msgType
.
# Configuration example
{
"id": "s1",
"type": "jsFilter",
"name": "Filter",
"configuration": {
"jsScript": "return msg.temperature > 50;"
}
}
2
3
4
5
6
7
8
# Application example
If msgType is: EVENT_APP1, then push the message to: http://192.168.136.26:9099/app1/api/msg, otherwise push to: http://192.168.136.26:9099/app2/api/msg
{
"ruleChain": {
"id":"rule01",
"name": "Test rule chain",
"root": true
},
"metadata": {
"nodes": [
{
"id": "s1",
"type": "jsFilter",
"name": "Filter",
"configuration": {
"jsScript": "return msgType =='EVENT_APP1';"
}
},
{
"id": "s2",
"type": "restApiCall",
"name": "Push data-app2",
"configuration": {
"restEndpointUrlPattern": "http://192.168.136.26:9099/app1/api/msg",
"requestMethod": "POST",
"maxParallelRequestsCount": 200
}
},
{
"id": "s3",
"type": "restApiCall",
"name": "Push data-app2",
"configuration": {
"restEndpointUrlPattern": "http://192.168.136.26:9099/app2/api/msg",
"requestMethod": "POST",
"maxParallelRequestsCount": 200
}
}
],
"connections": [
{
"fromId": "s1",
"toId": "s2",
"type": "True"
},
{
"fromId": "s1",
"toId": "s3",
"type": "False"
}
]
}
}
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51