根据配置的映射,重命名入站消息或其metadata中的键。
配置
字段说明
- 重命名键的位置 — 指定重命名发生的位置。可为:
- Message — 在消息 data 内重命名键。
- Message metadata — 在 metadata 内重命名键。
- Message keys mapping — 定义如何重命名键。每个映射包含:
- 当前键名 — 现有键的名称。
- 新键名 — 键将要改成的名称。
若当前键不存在,则跳过该映射。
JSON Schema
消息处理逻辑
- 根据配置确定在消息 data 还是 metadata 中重命名键。
- 对每个映射:
- 若键在所选源中存在:
- 将值复制到新键。
- 删除旧键。
- 若键在所选源中存在:
- 若至少重命名一个键:
- 创建包含更新后data或metadata的新消息。
- 若无键被重命名:
- 原样透传原始消息。
- 若发生意外错误,经
Failure路由消息。
输出连接
Success:- 处理正常完成(即使未重命名任何键)时。
Failure:- 处理过程中发生意外错误时。
示例
示例1 — 重命名消息data中的键
入站消息
Data:
1
2
3
{
"temperatureCelsius": 22.5
}
节点配置
1
2
3
4
5
6
{
"renameIn": "DATA",
"renameKeysMapping": {
"temperatureCelsius": "temperature"
}
}
出站消息
Data:
1
2
3
{
"temperature": 22.5
}
输出连接: Success。
说明: 消息data中的键 temperatureCelsius 被重命名为 temperature。
示例2 — 重命名消息metadata中的键
入站消息
Metadata:
1
2
3
{
"deviceModel": "BME250"
}
节点配置
1
2
3
4
5
6
{
"renameIn": "METADATA",
"renameKeysMapping": {
"deviceModel": "model"
}
}
出站消息
Metadata:
1
2
3
{
"model": "BME250"
}
输出连接: Success。
说明: metadata中的键 deviceModel 被重命名为 model。
示例3 — 键不存在 → 无更改
入站消息
Data:
1
2
3
{
"humidity": 55
}
节点配置
1
2
3
4
5
6
{
"renameIn": "DATA",
"renameKeysMapping": {
"temperatureCelsius": "temperature"
}
}
出站消息
Data:
1
2
3
{
"humidity": 55
}
输出连接: Success。
说明: 消息data中无匹配键;原始消息原样透传。
示例4 — 配置错误导致键覆盖
入站消息
Data:
1
2
3
4
{
"temperatureCelsius": 21.5,
"temperature": 99
}
节点配置
1
2
3
4
5
6
{
"renameIn": "DATA",
"renameKeysMapping": {
"temperatureCelsius": "temperature"
}
}
出站消息
Data:
1
2
3
{
"temperature": 21.5
}
输出连接: Success。
说明: 键 temperatureCelsius 被重命名为 temperature。原有的 temperature 键被新值 21.5 覆盖。此行为反映配置的映射,不作为错误处理。
示例5 — 重命名多个键(一个键未找到 → 跳过)
入站消息
Metadata:
1
2
3
4
{
"deviceName": "Boiler-21",
"deviceType": "Heater"
}
节点配置
1
2
3
4
5
6
7
8
{
"renameIn": "METADATA",
"renameKeysMapping": {
"deviceName": "name",
"deviceType": "type",
"firmwareVersion": "fw"
}
}
结果
1
2
3
4
{
"name": "Boiler-21",
"type": "Heater"
}
说明:
deviceName重命名为namedeviceType重命名为typefirmwareVersion在metadata中不存在,跳过且无错误