Skip to content

Commit

Permalink
docs:dubbo3 文档完成 (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun authored Mar 3, 2024
1 parent 5e276c8 commit 943f5e2
Show file tree
Hide file tree
Showing 21 changed files with 420 additions and 91 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
title: "元数据中心"
linkTitle: "元数据中心"
weight: 2
---


{{< notice tip >}} Dubbo 元数据中心仅适用于北极星服务端版本 >= 1.18.0 {{< /notice >}}

## Dubbo 分类

Dubbo当前常用的有2个分支版本,一个是apache dubbo(GroupID是org.apache.dubbo), 一个是dubbox (GroupID是com.alibaba)。两个分支的dubbo,对应不同的接入插件,大家接入之前可以先通过GroupID判断下当前项目依赖的是哪个分支的dubbo。


## Apache Dubbo 接入

### 支持版本

- dubbo 3.x 版本的接入,最新版本为 ```0.2.0-3.2.7```

### 引入依赖

在 pom.xml 中引入以下依赖

```xml
<!-- 北极星注册发现插件 -->
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>dubbo-registry-polaris</artifactId>
<version>${version}</version>
</dependency>
<!-- 北极星元数据中心插件 -->
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>dubbo-metadatareport-polaris</artifactId>
<version>${revision}</version>
</dependency>
```

### 参数配置

接下来,需要添加北极星 metadata-report 的配置,指定北极星的地址及相关配置信息,可以通过配置文件及代码的方式进行指定:

配置文件方式添加:

```properties
dubbo.metadata-report.address=polaris://127.0.0.1:8091
```

北极星地址的URL支持通过参数指定可选的配置,具体参数列表如下:

| 参数 | 类型 | 含义 |
|-----------|--------|------------------|
| namespace | string | 指定服务的命名空间 |
| token | string | 指定用户token |

### 结果验证

#### 服务接口定义

服务契约名称格式样例

```
"name": "dubbo::metadata::dubbo-provider::2e2e13eddf24272edcaa60c34afc5067",
"namespace": "dubbo",
"service": "dubbo-provider",
"protocol": "dubbo",
"version": "",
"revision": "2e2e13eddf24272edcaa60c34afc5067",
```

![](../图片/metadata/dubbo-interface-def.png)

#### 服务接口运维数据

服务契约名称格式样例

```
"name": "dubbo::metadata::1.0.0::provider::dubbo-provider",
"namespace": "dubbo",
"service": "dubbo-provider",
"protocol": "dubbo",
"version": "1.0.0",
"revision": "d297643d19dc4700a8c11d7fd57ef808",
```

![](../图片/metadata/dubbo-interface-admin.png)

#### 接口-应用映射

服务契约名称格式样例

```
"name": "dubbo::mapping::com.tencent.polaris.dubbo.api.HelloService",
"namespace": "dubbo",
"service": "",
"protocol": "dubbo",
"version": "",
"revision": "f31bc6a132c84ce9afc39c1b98fdb6a7",
```

查询该接口下有多少应用提供了该接口

```json
{
"@type": "type.googleapis.com/v1.ServiceContract",
"id": "535e686a7e8707b1d53e63f7578e80a2a94e4747",
"name": "dubbo::mapping::com.tencent.polaris.dubbo.api.HelloService",
"namespace": "dubbo",
"service": "",
"protocol": "dubbo",
"version": "",
"revision": "f31bc6a132c84ce9afc39c1b98fdb6a7",
"content": "",
"interfaces": [
{
"id": "6be61ef353a9e1918d5b84c100db0c8a5637f5a5",
"name": "dubbo-provider"
}
]
}
```
119 changes: 89 additions & 30 deletions content/zh-cn/docs/使用指南/java应用开发/dubbo/动态路由.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "动态路由"
linkTitle: "动态路由"
weight: 2
weight: 3
---

## Dubbo 分类
Expand All @@ -13,7 +13,7 @@ Dubbo当前常用的有2个分支版本,一个是apache dubbo(GroupID是org.
### 支持版本

- dubbo 2.x 版本的接入,最新版本为 ```0.2.2```
- dubbo 3.x 版本的接入,最新版本为 ```0.0.1-3.2.7```
- dubbo 3.x 版本的接入,最新版本为 ```0.2.0-3.2.7```

### 引入依赖

Expand Down Expand Up @@ -53,57 +53,116 @@ dubbo.registry.address=polaris://127.0.0.1:8091
{{% /tab %}}
{{< /tabs >}}

### 使用动态路由能力

*** 说明 ***
### 路由规则字段

动态路由可以实现基于dubbo的请求消息内容来对请求调度到不同的实例分组,比如将带了某些user标签的请求调度到灰度分组。

当前支持针对dubbo消息的以下内容进行路由调度:

> 应用级注册发现
| 消息类型 | dubbo消息内容 | 路由规则请求类型 |
|----------|----------------------------------------|----------------------------|
| 消息头 | attachment | 请求头(HEADER) |
| RPC接口 | dubbo interface 全限定名 | 路径(PATH) |
| RPC方法 | dubbo interface 下的具体某个方法的名称 | 请求匹配规则-方法(METHOD) |
| 请求体参数 | dubbo 方法入参某个字段 | 请求匹配规则-请求参数(QUERY) |

> 接口级注册发现
| 消息类型 | dubbo消息内容 | 路由规则请求类型 |
|--------|---------------|----------------|
| 消息头 | attachment | 请求头(HEADER) |
| RPC方法 | method | 路径(PATH) |
| 消息类型 | dubbo消息内容 | 路由规则请求类型 | |
|-------|---------------|---------------|---|
| 消息头 | attachment | 请求头(HEADER) | |
| RPC方法 | method | 方法(METHOD) |
| 请求体参数 | dubbo 方法入参某个字段 | 请求匹配规则-请求参数(QUERY),字段格式 |

> 应用级注册发现

| 消息类型 | dubbo消息内容 | 路由规则请求类型 |
|--------|---------------|----------------|
| 消息头 | attachment | 请求头(HEADER) |
| RPC方法 | method | 路径(PATH) |
### 功能验证

*** 配置路由规则 ***
动态路由样例包括3个工程,代表的是多个服务之间调用,调用链路为:front->middle->back。

配置自定义路由规则,指定带有附件user为archer的请求,路由到版本1.0.0的实例上
配置自定义路由规则,指定带有附件 user 为 polaris 的请求,路由到 env 为 gray 的实例上

![](../图片/路由规则.png)
![](../图片/router/dubbo-middle.png)

执行服务调用,调用时,需要设置一下当前请求的attachement。

```java
// 设置attachment,指定当前用户
RpcContext.getContext().setAttachment("user", userName);
String message = service.sayHello("hello");
System.out.printf("message from %s is %s%n", userName, message);
public String doSayHello(String name) {
RpcContext.getClientAttachment().setAttachment("user", name);
return greetingService.sayHello(name);
}
```

### 样例
代码中无需额外添加路由判断代码,插件会自动在被调端进行请求信息进行路由。

动态路由样例包括3个工程,代表的是多个服务之间调用,调用链路为:front->middle->back。
最终路由效果

{{< tabs >}}
{{% tab name="dubbo2.x" %}}
- front工程:[dubbo-router-front](https://github.com/polarismesh/dubbo-java-polaris/tree/main/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-front)
- middle工程:[dubbo-router-middle](https://github.com/polarismesh/dubbo-java-polaris/tree/main/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-middle)
- back工程:[dubbo-router-back](https://github.com/polarismesh/dubbo-java-polaris/tree/main/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-back)
{{% tab name="未设置路由规则" %}}

```log
➜ ~ curl http://127.0.0.1:15700/echo\?method\=sayHi\&value\=123
[FrontService] sayHi, 123 -> [MiddleService-gray] sayHello, 123 -> [BackendService-gray] sayHello, 123%
➜ ~ curl http://127.0.0.1:15700/echo\?method\=sayHi\&value\=123
[FrontService] sayHi, 123 -> [MiddleService-gray] sayHello, 123 -> [BackendService-gray] sayHello, 123%
➜ ~ curl http://127.0.0.1:15700/echo\?method\=sayHi\&value\=123
[FrontService] sayHi, 123 -> [MiddleService-normal] sayHello, 123 -> [BackendService-normal] sayHello, 123%
➜ ~ curl http://127.0.0.1:15700/echo\?method\=sayHi\&value\=123
[FrontService] sayHi, 123 -> [MiddleService-normal] sayHello, 123 -> [BackendService-normal] sayHello, 123%
➜ ~ curl http://127.0.0.1:15700/echo\?method\=sayHi\&value\=123
[FrontService] sayHi, 123 -> [MiddleService-gray] sayHello, 123 -> [BackendService-normal] sayHello, 123%
➜ ~ curl http://127.0.0.1:15700/echo\?method\=sayHi\&value\=123
[FrontService] sayHi, 123 -> [MiddleService-gray] sayHello, 123 -> [BackendService-normal] sayHello, 123%
➜ ~ curl http://127.0.0.1:15700/echo\?method\=sayHi\&value\=123
[FrontService] sayHi, 123 -> [MiddleService-gray] sayHello, 123 -> [BackendService-gray] sayHello, 123%
```

{{% /tab %}}
{{% tab name="设置路由但未命中规则" %}}

```log
➜ ~ curl http://127.0.0.1:15700/echo\?method\=sayHi\&value\=123
[FrontService] sayHi, 123 -> [MiddleService-gray] sayHello, 123 -> [BackendService-gray] sayHello, 123%
➜ ~ curl http://127.0.0.1:15700/echo\?method\=sayHi\&value\=123
[FrontService] sayHi, 123 -> [MiddleService-gray] sayHello, 123 -> [BackendService-gray] sayHello, 123%
➜ ~ curl http://127.0.0.1:15700/echo\?method\=sayHi\&value\=123
[FrontService] sayHi, 123 -> [MiddleService-normal] sayHello, 123 -> [BackendService-normal] sayHello, 123%
➜ ~ curl http://127.0.0.1:15700/echo\?method\=sayHi\&value\=123
[FrontService] sayHi, 123 -> [MiddleService-normal] sayHello, 123 -> [BackendService-normal] sayHello, 123%
➜ ~ curl http://127.0.0.1:15700/echo\?method\=sayHi\&value\=123
[FrontService] sayHi, 123 -> [MiddleService-gray] sayHello, 123 -> [BackendService-normal] sayHello, 123%
➜ ~ curl http://127.0.0.1:15700/echo\?method\=sayHi\&value\=123
[FrontService] sayHi, 123 -> [MiddleService-gray] sayHello, 123 -> [BackendService-normal] sayHello, 123%
➜ ~ curl http://127.0.0.1:15700/echo\?method\=sayHi\&value\=123
[FrontService] sayHi, 123 -> [MiddleService-gray] sayHello, 123 -> [BackendService-gray] sayHello, 123%
```


{{% /tab %}}
{{% tab name="设置路由且命中规则" %}}

```log
➜ .dubbo curl http://127.0.0.1:15700/echo\?method\=sayHi\&value\=polaris
[FrontService] sayHi, polaris -> [MiddleService-gray] sayHello, polaris -> [BackendService-gray] sayHello, polaris%
➜ .dubbo curl http://127.0.0.1:15700/echo\?method\=sayHi\&value\=polaris
[FrontService] sayHi, polaris -> [MiddleService-gray] sayHello, polaris -> [BackendService-gray] sayHello, polaris%
➜ .dubbo curl http://127.0.0.1:15700/echo\?method\=sayHi\&value\=polaris
[FrontService] sayHi, polaris -> [MiddleService-gray] sayHello, polaris -> [BackendService-gray] sayHello, polaris%
➜ .dubbo curl http://127.0.0.1:15700/echo\?method\=sayHi\&value\=polaris
[FrontService] sayHi, polaris -> [MiddleService-gray] sayHello, polaris -> [BackendService-gray] sayHello, polaris%
➜ .dubbo curl http://127.0.0.1:15700/echo\?method\=sayHi\&value\=polaris
[FrontService] sayHi, polaris -> [MiddleService-gray] sayHello, polaris -> [BackendService-gray] sayHello, polaris%
```


{{% /tab %}}
{{% tab name="dubbo3.x" %}}
{{% /tabs %}}


路由样例包括 3 个工程。

- front工程:[dubbo-router-front](https://github.com/polarismesh/dubbo-java-polaris/tree/main/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-front)
- middle工程:[dubbo-router-middle](https://github.com/polarismesh/dubbo-java-polaris/tree/main/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-middle)
- back工程:[dubbo-router-back](https://github.com/polarismesh/dubbo-java-polaris/tree/main/dubbo/dubbo-examples/dubbo-router-example/dubbo-router-back)
{{% /tab %}}
{{< /tabs >}}

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Dubbo当前常用的有2个分支版本,一个是apache dubbo(GroupID是org.
### 支持版本

- dubbo 2.x 版本的接入,最新版本为 ```0.2.2```
- dubbo 3.x 版本的接入,最新版本为 ```0.0.1-3.2.7```
- dubbo 3.x 版本的接入,最新版本为 ```0.2.0-3.2.7```

### 引入依赖

Expand Down Expand Up @@ -100,22 +100,14 @@ dubbo.registry.address=polaris://127.0.0.1:8091
{{< tabs >}}
{{% tab name="应用级注册发现" %}}
[dubbo-discovery-provider](https://github.com/polarismesh/dubbo-java-polaris/tree/dubbo-3.2.x/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-quick-provider)

![](../图片/discovery/dubbo-application.png)
{{% /tab %}}
{{% tab name="接口级注册发现" %}}
[dubbo-discovery-provider](https://github.com/polarismesh/dubbo-java-polaris/tree/dubbo-2.x/dubbo/dubbo-examples/dubbo-discovery-example/dubbo-discovery-provider)
{{% /tab %}}

{{< /tabs >}}

注册后,可以在北极星控制台看到注册后的效果:

{{< tabs >}}
{{% tab name="应用级注册发现" %}}
![](../图片/服务注册.png)
![](../图片/discovery/dubbo-interface.png)

{{% /tab %}}
{{% tab name="接口级注册发现" %}}
![](../图片/服务注册.png)

{{% /tab %}}
{{< /tabs >}}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 943f5e2

Please sign in to comment.