nacos
- 并行发送请求。
在文件 中添加以下配置到:
也可以这样简洁配置(未配置项使用默认值):
discovery:
nacos:
host:
- "http://192.168.33.1:8848"
$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
"uri": "/nacos/*",
"upstream": {
"service_name": "APISIX-NACOS",
"type": "roundrobin",
"discovery_type": "nacos"
}
}'
响应如下:
指定命名空间
例如,转发 URI 匹配 “/nacosWithNamespaceId/*“ 的请求到一个上游服务, 该服务在 Nacos 中的服务名是 APISIX-NACOS,命名空间是 test_ns,查询地址是 ,创建路由时指定服务发现类型为 nacos 。
$ curl http://127.0.0.1:9080/apisix/admin/routes/2 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
"uri": "/nacosWithNamespaceId/*",
"upstream": {
"service_name": "APISIX-NACOS",
"type": "roundrobin",
"discovery_type": "nacos",
"discovery_args": {
"namespace_id": "test_ns"
}
}'
{
"node": {
"key": "\/apisix\/routes\/2",
"id": "2",
"create_time": 1615796097,
"status": 1,
"update_time": 1615799165,
"upstream": {
"hash_on": "vars",
"pass_host": "pass",
"scheme": "http",
"service_name": "APISIX-NACOS",
"type": "roundrobin",
"discovery_type": "nacos",
"discovery_args": {
"namespace_id": "test_ns"
}
},
"priority": 0,
"uri": "\/nacosWithNamespaceId\/*"
}
},
"action": "set"
}
指定组
例如,转发 URI 匹配 “/nacosWithGroupName/*“ 的请求到一个上游服务, 该服务在 Nacos 中的服务名是 APISIX-NACOS,组名是 test_group,查询地址是 ,创建路由时指定服务发现类型为 nacos 。
响应如下:
{
"node": {
"key": "\/apisix\/routes\/3",
"value": {
"id": "3",
"status": 1,
"upstream": {
"hash_on": "vars",
"pass_host": "pass",
"scheme": "http",
"service_name": "APISIX-NACOS",
"type": "roundrobin",
"discovery_type": "nacos",
"discovery_args": {
"group_name": "test_group"
}
},
"priority": 0,
"uri": "\/nacosWithGroupName\/*"
}
},
"action": "set"
}
同时指定命名空间和组
$ curl http://127.0.0.1:9080/apisix/admin/routes/4 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
"uri": "/nacosWithNamespaceIdAndGroupName/*",
"upstream": {
"service_name": "APISIX-NACOS",
"type": "roundrobin",
"discovery_type": "nacos",
"discovery_args": {
"namespace_id": "test_ns",
"group_name": "test_group"
}
响应如下: