You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2021/09/09 02:45:04 UTC

[apisix] branch master updated: docs(discovery): add eureka and nacos (#5018)

This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 579ef5a  docs(discovery): add eureka and nacos (#5018)
579ef5a is described below

commit 579ef5ad98bd5fa4e1f450f2615ef1af7b674158
Author: okaybase <75...@users.noreply.github.com>
AuthorDate: Thu Sep 9 10:44:55 2021 +0800

    docs(discovery): add eureka and nacos (#5018)
---
 docs/zh/latest/config.json         |   4 +-
 docs/zh/latest/discovery/eureka.md |  25 ++++
 docs/zh/latest/discovery/nacos.md  | 260 +++++++++++++++++++++++++++++++++++++
 3 files changed, 288 insertions(+), 1 deletion(-)

diff --git a/docs/zh/latest/config.json b/docs/zh/latest/config.json
index 93cd5a8..8c6a307 100644
--- a/docs/zh/latest/config.json
+++ b/docs/zh/latest/config.json
@@ -147,7 +147,9 @@
           "type": "category",
           "label": "Discovery",
           "items": [
-            "discovery"
+            "discovery",
+            "discovery/nacos",
+            "discovery/eureka"
           ]
         },
         {
diff --git a/docs/zh/latest/discovery/eureka.md b/docs/zh/latest/discovery/eureka.md
new file mode 100644
index 0000000..a7a1600
--- /dev/null
+++ b/docs/zh/latest/discovery/eureka.md
@@ -0,0 +1,25 @@
+---
+title: eureka
+---
+
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+Apache APISIX 支持使用 [Eureka](https://github.com/Netflix/eureka#eureka) 做服务发现。
+详情请阅读 [支持的服务注册发现](../discovery.md#当前支持的注册中心) 。
diff --git a/docs/zh/latest/discovery/nacos.md b/docs/zh/latest/discovery/nacos.md
new file mode 100644
index 0000000..ddec790
--- /dev/null
+++ b/docs/zh/latest/discovery/nacos.md
@@ -0,0 +1,260 @@
+---
+title: nacos
+---
+
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+## 基于 [Nacos](https://nacos.io/zh-cn/docs/what-is-nacos.html) 的服务发现
+
+Nacos 服务发现模块目前是实验性的。
+
+当前模块的性能有待改进:
+
+1. 并行发送请求。
+
+### Nacos 配置
+
+在文件 `conf/config.yaml`  中添加以下配置到:
+
+```yaml
+discovery:
+  nacos:
+    host:
+      - "http://${username}:${password}@${host1}:${port1}"
+    prefix: "/nacos/v1/"
+    fetch_interval: 30    # default 30 sec
+    weight: 100           # default 100
+    timeout:
+      connect: 2000       # default 2000 ms
+      send: 2000          # default 2000 ms
+      read: 5000          # default 5000 ms
+```
+
+也可以这样简洁配置(未配置项使用默认值):
+
+```yaml
+discovery:
+  nacos:
+    host:
+      - "http://192.168.33.1:8848"
+```
+
+### Upstream 设置
+
+例如,转发 URI 匹配 "/nacos/*" 的请求到一个上游服务,
+该服务在 Nacos 中的服务名是 APISIX-NACOS ,查询地址是 http://192.168.33.1:8848/nacos/v1/ns/instance/list?serviceName=APISIX-NACOS ,创建路由时指定服务发现类型为 nacos 。
+
+```shell
+$ 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"
+    }
+}'
+```
+
+响应如下:
+
+```json
+{
+  "node": {
+    "key": "\/apisix\/routes\/1",
+    "value": {
+      "id": "1",
+      "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"
+      },
+      "priority": 0,
+      "uri": "\/nacos\/*"
+    }
+  },
+  "action": "set"
+}
+```
+
+### 参数
+
+| 名字         | 类型   | 可选项 | 默认值 | 有效值 | 说明                                                  |
+| ------------ | ------ | ----------- | ------- | ----- | ------------------------------------------------------------ |
+| namespace_id | string | 可选    | public     |       | 服务所在的命名空间 |
+| group_name   | string | 可选    | DEFAULT_GROUP       |       | 服务所在的组 |
+
+#### 指定命名空间
+
+例如,转发 URI 匹配 "/nacosWithNamespaceId/*" 的请求到一个上游服务,
+该服务在 Nacos 中的服务名是 APISIX-NACOS,命名空间是 test_ns,查询地址是 http://192.168.33.1:8848/nacos/v1/ns/instance/list?serviceName=APISIX-NACOS&namespaceId=test_ns ,创建路由时指定服务发现类型为 nacos 。
+
+```shell
+$ 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"
+        }
+    }
+}'
+```
+
+响应如下:
+
+```json
+{
+  "node": {
+    "key": "\/apisix\/routes\/2",
+    "value": {
+      "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,查询地址是 http://192.168.33.1:8848/nacos/v1/ns/instance/list?serviceName=APISIX-NACOS&groupName=test_group ,创建路由时指定服务发现类型为 nacos 。
+
+```shell
+$ curl http://127.0.0.1:9080/apisix/admin/routes/3 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
+{
+    "uri": "/nacosWithGroupName/*",
+    "upstream": {
+        "service_name": "APISIX-NACOS",
+        "type": "roundrobin",
+        "discovery_type": "nacos",
+        "discovery_args": {
+          "group_name": "test_group"
+        }
+    }
+}'
+```
+
+响应如下:
+
+```json
+{
+  "node": {
+    "key": "\/apisix\/routes\/3",
+    "value": {
+      "id": "3",
+      "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": {
+          "group_name": "test_group"
+        }
+      },
+      "priority": 0,
+      "uri": "\/nacosWithGroupName\/*"
+    }
+  },
+  "action": "set"
+}
+```
+
+#### 同时指定命名空间和组
+
+例如,转发 URI 匹配 "/nacosWithNamespaceIdAndGroupName/*" 的请求到一个上游服务,
+该服务在 Nacos 中的服务名是 APISIX-NACOS,命名空间是 test_ns,组名是 test_group,查询地址是 http://192.168.33.1:8848/nacos/v1/ns/instance/list?serviceName=APISIX-NACOS&namespaceId=test_ns&groupName=test_group ,创建路由时指定服务发现类型为 nacos 。
+
+```shell
+$ 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"
+        }
+    }
+}'
+```
+
+响应如下:
+
+```json
+{
+  "node": {
+    "key": "\/apisix\/routes\/4",
+    "value": {
+      "id": "4",
+      "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",
+          "group_name": "test_group"
+        }
+      },
+      "priority": 0,
+      "uri": "\/nacosWithNamespaceIdAndGroupName\/*"
+    }
+  },
+  "action": "set"
+}
+```