Component Configuration Variables
# Component Configuration Variables
In certain scenarios, it’s necessary to uniformly modify component configurations or dynamically replace them during component runtime. You can achieve this by using built-in variables to substitute component configurations. The syntax is as follows: ${key} or ${key.subKey}.
# Global Variables
Global variables
are executed for replacement logic during component initialization (when the component's Init method is executed), including the following variables:
global
variable: Access values from config.Properties, for example,${global.key}
.vars
variable: Access values from rule chain vars, for example,${vars.key}
.
Global Variables: All component configuration fields support variable substitution.
# Runtime Variables
Runtime Variables
are executed for replacement logic during component runtime (when the component's OnMsg method is executed), including the following variables:
id
variable: Access the message ID.ts
variable: Access the message timestamp.data
variable: Access the original message content.msg
variable: Access the transformed message data. If the message's dataType is JSON, you can access fields using${msg.key}
.metadata
variable: Access message metadata, e.g.,${metadata.key}
.type
variable: Access the message type.dataType
variable: Access the data type.
Runtime Variables: Only specific component configuration fields, as indicated, support variable substitution.
# Example
{
"ruleChain": {
"id":"rule01",
"name": "test",
"configuration": {
"vars": {
"topicPrefix":"/device/msg"
}
}
},
"metadata": {
"nodes": [
{
"id": "s2",
"type": "mqttClient",
"name": "push data",
"configuration": {
"server": "${global.mqttServer}",
"topic": "${vars.topicPrefix}/${metadata.deviceId}"
}
}
],
"connections": [
{
}
]
}
}
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