Nacos 服务调用
x/nacosServiceCall 组件:通过 nacos 服务发现定位健康实例,按 HTTP 方法调用集群微服务,响应写入 msg.Data,成功走 Success、失败(含 HTTP ≥ 400)走 Failure。
# 配置
继承 公共连接配置,额外字段:
| 字段 | 类型 | 说明 | 默认值 |
|---|---|---|---|
| serviceName | string | nacos 注册的服务名 | 无(必填) |
| groupName | string | 服务分组 | DEFAULT_GROUP |
| method | string | HTTP 方法(GET/POST/PUT/DELETE/PATCH) | GET |
| path | string | 请求路径,支持 ${msg.xx} | 空 |
| body | string | 请求体,支持 ${msg.xx};留空则用 msg.Data | 空 |
# 行为
- 实例选址:从 nacos 选取健康实例并轮询负载均衡。
- 请求体:配置了
body(含${}模板或固定串)则按配置渲染;留空则把当前消息内容(msg.Data)作为请求体透传给后端。 - 响应:后端响应体写入
msg.Data;HTTP 状态码 ≥ 400 触发Failure。 - 超时:HTTP 调用受公共配置
timeout(秒)限制,超时触发Failure。
# 示例
GET 调用注册到 nacos 的 user-service:
{
"id": "call_user",
"type": "x/nacosServiceCall",
"configuration": {
"server": "127.0.0.1:8848",
"serviceName": "user-service",
"groupName": "DEFAULT_GROUP",
"method": "GET",
"path": "/info"
}
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
POST 带请求体(模板取消息字段):
{
"id": "create_order",
"type": "x/nacosServiceCall",
"configuration": {
"server": "127.0.0.1:8848",
"serviceName": "order-service",
"method": "POST",
"path": "/orders",
"body": "${msg.payload}"
}
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 关联组件
- 配置读取:x/nacosConfigGet
- 配置写入:x/nacosConfigSet
- 配置变更监听:endpoint/nacos
在 GitHub 上编辑此页 (opens new window)
上次更新: 2026/08/02, 04:56:51