Nacos 配置写入
x/nacosConfigSet 组件:全量写入(发布)nacos 配置——不存在则创建、存在则覆盖。成功走 Success、失败走 Failure。
# 配置
继承 公共连接配置,额外字段:
| 字段 | 类型 | 说明 | 默认值 |
|---|---|---|---|
| dataId | string | 配置 Data ID | 无(必填) |
| group | string | 配置分组 | DEFAULT_GROUP |
| content | string | 配置内容,支持 ${msg.xx} | 空 |
| format | string | 配置格式:json/yaml/properties/text | json |
# 行为
- 全量覆盖:nacos 配置以文本存储,写入即整段替换原内容(nacos 本身不感知内部结构,无字段级 API)。
- 模板:
content支持${msg.xx}动态渲染。 - 改某个字段:需「读-改-写」组合,见下文示例。
# 输出
写入成功后 msg 原样向 Success 流转(节点不读回内容)。
# 示例
全量写入固定配置:
{
"id": "set_cfg",
"type": "x/nacosConfigSet",
"configuration": {
"server": "127.0.0.1:8848",
"dataId": "app.json",
"group": "DEFAULT_GROUP",
"content": "{\"featureX\":true}",
"format": "json"
}
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 读-改-写(只改某个字段)
x/nacosConfigGet 读原配置 → jsTransform 解析改字段 → x/nacosConfigSet 全量写回:
{
"ruleChain": {"name": "config-patch", "root": true},
"metadata": {
"nodes": [
{"id": "g", "type": "x/nacosConfigGet", "configuration": {
"server": "127.0.0.1:8848", "dataId": "app.json"}},
{"id": "p", "type": "jsTransform", "configuration": {
"jsScript": "var c=JSON.parse(msg); c.featureX=true; return {msg:JSON.stringify(c),metadata:metadata,msgType:msgType};"}},
{"id": "s", "type": "x/nacosConfigSet", "configuration": {
"server": "ref://g", "dataId": "app.json", "format": "json", "content": "${msg}"}}
],
"connections": [
{"fromId": "g", "toId": "p", "type": "Success"},
{"fromId": "p", "toId": "s", "type": "Success"}
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
读-改-写非原子,并发写同一 dataId 可能「后写覆盖前写」;配置变更通常低频,风险很小。
# 关联组件
- 服务调用:x/nacosServiceCall
- 配置读取:x/nacosConfigGet
- 配置变更监听:endpoint/nacos
在 GitHub 上编辑此页 (opens new window)
上次更新: 2026/08/01, 05:05:14