Skip to content

Commit

Permalink
update doc (#2941)
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenlj committed Mar 19, 2024
1 parent 8b54e72 commit ebc331d
Show file tree
Hide file tree
Showing 72 changed files with 1,946 additions and 1,496 deletions.
40 changes: 23 additions & 17 deletions content/zh-cn/overview/mannual/java-sdk/quick-start/starter.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ $ cd dubbo-samples/11-quickstart
````
{{% /alert %}}

## 本地启动应用
接下来,让我们尝试在本地启动应用。运行以下命令启动应用:

```shell
./mvnw
```

{{% alert title="注意" color="warning" %}}
由于配置文件中启用了注册中心,为了能够成功启动应用,您需要首先在本地启动 <a href="/zh-cn/overview/reference/integrations/nacos/" target="_blank_">Nacos</a><a href="/zh-cn/overview/reference/integrations/zookeeper/" target="_blank_">Zookeeper</a> 注册中心 server。
{{% /alert %}}


在应用启动成功后,本地进程使用 <a href="/zh-cn/overview/reference/protocols/triple/" target="_blank_">Triple </a>协议在指定端口发布了服务,可直接使用 cURL 测试服务是否已经正常运行:

```shell
curl \
--header "Content-Type: application/json" \
--data '["Dubbo"]' \
http://localhost:50051/com.example.demo.dubbo.api.DemoService/sayHello/
```

除了使用命令行之外,我们还可以在 IDE 中启动项目,调整示例或进行本地 debug。

## 源码解析
将以上准备好的示例项目导入最喜欢的 IDE 开发工具(以 IntelliJ IDEA 为例),项目结构如下:

Expand Down Expand Up @@ -139,23 +162,6 @@ public class DemoApplication {
}
```

## 本地启动应用
接下来,让我们尝试在本地启动应用。

{{% alert title="注意" color="warning" %}}
由于配置文件中启用了注册中心,为了能够成功启动应用,您需要首先在本地启动 <a href="https://nacos.io/zh-cn/docs/v2/quickstart/quick-start.html" target="_blank_">Nacos</a><a href="https://zookeeper.apache.org/doc/current/zookeeperStarted.html" target="_blank_">Zookeeper</a> 注册中心 server。
{{% /alert %}}

在应用启动成功后,本地进程使用 <a href="/zh-cn/overview/reference/protocols/triple/" target="_blank_">Triple </a>协议在指定端口发布了服务,可直接使用 cURL 测试服务是否已经正常运行:


```shell
curl \
--header "Content-Type: application/json" \
--data '["Dubbo"]' \
http://localhost:50051/com.example.demo.dubbo.api.DemoService/sayHello/
```

## 发布服务定义到远端仓库

应用开发完成后,我们需要将服务定义发布到外部公开的或组织内部的 maven 仓库,以便调用这些服务的应用能够加载并使用这些服务。
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
---
description: "Dubbo 单端口多协议实现原理&源码解析。"
linkTitle: 单端口多协议
title: 单端口多协议实现原理解析
type: docs
weight: 1
---

通过对protocol进行配置,dubbo3可以支持端口的协议复用。
比如使用Triple协议启动端口复用后,可以在相同的端口上为服务增加
Dubbo协议支持,以及Qos协议支持。这些协议的识别都是由一个统一的端口复用
服务器进行处理的,可以用于服务的协议迁移,并且可以节约端口以及相关的资源,减少运维的复杂性。

![pu-server-image1](/imgs/blog/pu-server/pu-server-flow.png)

- 在服务的创建阶段,通过从Config层获取到服务导出的协议配置从而创建不同的Protocol对象进行导出。在导出的过程
中,如果不是第一次创建端口复用的Server,那么Exchanger会将Protcol层传递的数据保存到Server,用于后续处理该协议类型的消息。

- 当客户端的消息传递过来后,首先会通过Server传递给ProtocolDetector,如果完成了识别,那么就会标记该客户端为对应的协议。并通过WireProtocol配置对应的处理逻辑,最后交给ChannelOperator完成底层的IO框架和对应的Dubbo框架的处理逻辑的绑定。

- 以上的协议识别完成之后,Channel已经确定了如何处理远程的客户端消息,通过对应的ServerPipeline进行处理即可(在处理的过程中也会根据配置信息决定消息的处理线程)。

## 使用场景
- 最常用的是用于服务发现。这允许应用程序通过网络发现服务,然后使用同一端口与它们通信,有助于降低网络通信的复杂性,并使其更易于管理。

- 可以用于负载平衡。这允许应用程序在多个远程服务或服务集群之间平衡负载,有助于提高服务的可扩展性、可靠性和可用性。

- 可以用于服务监控。这允许应用程序监视远程服务的运行状况,并在服务出现故障或变得不可用时发出警报,有助于确保服务的可用性并减少停机时间。

> 参考用例
[https://github.com/apache/dubbo-samples/tree/master/dubbo-samples-port-unification](https://github.com/apache/dubbo-samples/tree/master/3-extensions/protocol/dubbo-samples-port-unification)

## 使用方式
在同一主机上部署多个服务或需要通过负载均衡器访问多个服务。

> 关于Dubbo支持的配置方式 [配置说明](/zh-cn/overview/mannual/java-sdk/reference-manual/config/)
### 服务多协议导出

ext-protocol参数支持配置多个不同的协议,协议之间通过","进行分隔。

#### xml 配置

```xml
<dubbo:protocol name="dubbo" port="-1" ext-protocol="tri,"/>

<bean id="greetingService" class="org.apache.dubbo.demo.provider.GreetingServiceImpl"/>

<dubbo:service delay="5000" version="1.0.0" group="greeting" timeout="5000" interface="org.apache.dubbo.demo.GreetingService" ref="greetingService" protocol="dubbo"/>

```

#### API 配置

```java
ProtocolConfig config = new ProtocolConfig(CommonConstants.TRIPLE, -1);

config.setExtProtocol(CommonConstants.DUBBO+",");
```

#### yaml 配置

``` yaml
dubbo:
application:
name: dubbo-springboot-demo-provider
protocol:
name: tri
port: -1
ext-protocol: dubbo,
```

#### properties 配置
```properties
dubbo.protocol.name=tri
dubbo.protocol.ext-protocol=dubbo,
dubbo.protocol.port=20880
```

### Qos接入

#### Qos模块导入

```xml
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-qos</artifactId>
</dependency>
```

完成Qos模块的导入之后,相关的配置项可参考[Qos操作手册](/zh-cn/overview/mannual/java-sdk/reference-manual/qos/overview/)进行配置。

默认情况下,基于端口复用的Qos服务在模块导入后是启动的。



### Qos使用

将Qos协议接入到端口复用的场景下,需要在建立连接之后,客户端先向服务端发送消息,对比将Qos协议通过单个端口提供服务,端口复用版的Qos协议在处理telnet连接的情况下需要用户执行一些操作,完成协议识别(二选一)。

1. 直接调用命令

直接调用telnet支持的命令也可以完成识别,在用户不熟悉的情况下可以调用help指令完成识别

![pu-server-image2](/imgs/blog/pu-server/qos-telnet-directcall.png)

2. 发送telnet命令识别

通过telnet命令建立连接之后,执行以下几个步骤:

1. 使用 crtl + "]" 进入到telnet交互界面(telnet默认的escape character)
2. 调用 "send ayt" 向服务端发送特殊识别字段(为telnet协议的一个特殊字段)
3. 回车完成消息发送并进入到dubbo的交互界面

![pu-server-imgs3](/imgs/blog/pu-server/qos-telnet-sendayt.png)


### 服务引用

[dubbo-samples-port-unification](https://github.com/apache/dubbo-samples/tree/master/3-extensions/protocol/dubbo-samples-port-unification)中的例子作为基础, 引用不同协议的服务和非端口复用情况下的配置是一致的,下面通过Consumer端的InvokerListener输出调用过程中的URL信息。

```java
ReferenceConfig<GreetingService> reference = new ReferenceConfig<>();
reference.setInterface(GreetingService.class);
reference.setListener("consumer");
reference.setProtocol(this.protocol);
// reference.setProtocol(CommonConstants.DUBBO);
// reference.setProtocol(CommonConstants.TRIPLE);
```

![pu-server-imgs4](/imgs/blog/pu-server/reference-service.png)

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ weight: 1

配置中心 (config-center) 在 Dubbo 中可承担两类职责:

1. [外部化配置](../config/principle/#33-外部化配置):启动配置的集中式存储 (简单理解为 dubbo.properties 的外部化存储)。
1. [外部化配置](/zh-cn/overview/mannual/java-sdk/reference-manual/config/principle/#33-外部化配置):启动配置的集中式存储 (简单理解为 dubbo.properties 的外部化存储)。
2. 流量治理规则存储

请参考具体扩展实现了解如何启用配置中心。
Expand All @@ -22,6 +22,8 @@ weight: 1
* namespace - 配置命名空间,默认值 `dubbo`。命名空间通常用于多租户隔离,即对不同用户、不同环境或完全不关联的一系列配置进行逻辑隔离,区别于物理隔离的点是不同的命名空间使用的还是同一物理集群。
* group - 配置分组,默认值 `dubbo``group` 通常用于归类一组相同类型/目的的配置项,是对 `namespace` 下配置项的进一步隔离。

参考 [配置说明 - 配置项手册](../config/properties/#config-center) 了解 namespace 和 group 之外 config-center 开放的更多配置项。
参考 [配置说明 - 配置项手册](/zh-cn/overview/mannual/java-sdk/reference-manual/config/properties/#dubboconfig-center) 了解 namespace 和 group 之外 config-center 开放的更多配置项。

> 为了兼容 2.6.x 版本配置,在使用 Zookeeper 作为注册中心,且没有显式配置配置中心的情况下,Dubbo 框架会默认将此 Zookeeper 用作配置中心,但将只作服务治理用途。
{{% alert title="使用注册中心作为默认配置中心" color="info" %}}
在使用 Zookeeper、Nacos 作为注册中心且没有显式配置配置中心的情况下,Dubbo 框架会默认将此 Zookeeper、Nacos 用作配置中心,用作服务治理用途。
{{% /alert %}}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ weight: 3
---

## 1 前置条件
* 了解 [Dubbo 基本开发步骤](../../../quick-start/spring-boot/)
* 安装并启动 [Nacos](https://nacos.io/zh-cn/docs/quick-start.html)
> 当Dubbo使用`3.0.0`及以上版本时,需要使用Nacos `2.0.0`及以上版本。
* 了解 [Dubbo 基本开发步骤](/zh-cn/overview/mannual/java-sdk/quick-start/starter/)
* 安装并启动 [Nacos](/zh-cn/overview/reference/integrations/nacos/)

> 当Dubbo使用`3.0.0`及以上版本时,需要使用Nacos `2.0.0`及以上版本。请参考 [nacos 注册中心](/zh-cn/overview/mannual/java-sdk/reference-manual/registry/nacos/#12-nacos-版本) 了解 nacos 版本适配情况。
## 2 使用说明

### 2.1 增加 Maven 依赖
如果项目已经启用 Nacos 作为注册中心,则无需增加任何额外配置。

如果未启用 Nacos 注册中心,则请参考 [为注册中心增加 Nacos 依赖](../../registry/nacos/#21-增加依赖)
如果未启用 Nacos 注册中心,则请参考 [为注册中心增加 Nacos 依赖](/zh-cn/overview/mannual/java-sdk/reference-manual/registry/nacos/#11-增加依赖)

### 2.2 启用 Nacos 配置中心
```xml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
description: "更多配置中心扩展实现,包括 etcd、consul 等"
linkTitle: 扩展实现
title: 更多配置中心扩展实现
type: docs
weight: 4
---

Dubbo 框架还默认提供了 etcd、consul 等配置中心适配实现。

## Etcd

Etcd 配置中心由社区生态库维护,具体可参见 [](https://github.com/apache/dubbo-spi-extensions/tree/master/dubbo-configcenter-extensions/dubbo-configcenter-etcd)

增加依赖:

```xml
<dependency>
<groupId>org.apache.dubbo.extensions</groupId>
<artifactId>dubbo-configcenter-etcd</artifactId>
<version>3.3.0</version>
</dependency>
```

调整配置:

```yaml
dubbo
config-center
address: etcd://127.0.0.1:1111
```


## Consul

Consul 配置中心由社区生态库维护,具体可参见 [](https://github.com/apache/dubbo-spi-extensions/tree/master/dubbo-configcenter-extensions/dubbo-configcenter-consul)

增加依赖:

```xml
<dependency>
<groupId>org.apache.dubbo.extensions</groupId>
<artifactId>dubbo-configcenter-consul</artifactId>
<version>3.3.0</version>
</dependency>
```

调整配置:

```yaml
dubbo
config-center
address: consul://127.0.0.1:1111
```
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ weight: 2


## 1 前置条件
* 了解 [Dubbo 基本开发步骤](../../../quick-start/spring-boot/)
* 安装并启动 [Zookeeper](https://zookeeper.apache.org/)
* 了解 [Dubbo 基本开发步骤](/zh-cn/overview/mannual/java-sdk/quick-start/starter/)
* 安装并启动 [Zookeeper](/zh-cn/overview/reference/integrations/zookeeper/)

## 2 使用说明
在此查看[完整示例代码](https://github.com/apache/dubbo-samples/tree/master/3-extensions/configcenter/dubbo-samples-configcenter-annotation)

### 2.1 增加 Maven 依赖
如果项目已经启用 Zookeeper 作为注册中心,则无需增加任何额外配置。

如果未使用 Zookeeper 注册中心,则请参考 [为注册中心增加 Zookeeper 相关依赖](../../registry/zookeeper/#21-增加-maven-依赖)
如果未使用 Zookeeper 注册中心,则请参考 [为注册中心增加 Zookeeper 相关依赖](/zh-cn/overview/mannual/java-sdk/reference-manual/registry/zookeeper/#11-增加-maven-依赖)

### 2.2 启用 Zookeeper 配置中心
```xml
Expand Down Expand Up @@ -49,10 +49,10 @@ ConfigCenterConfig configCenter = new ConfigCenterConfig();
configCenter.setAddress("zookeeper://127.0.0.1:2181");
```

`address` 格式请参考 [zookeeper 注册中心 - 启用配置](../../registry/zookeeper/#22-配置并启用-zookeeper)
`address` 格式请参考 [zookeeper 注册中心 - 启用配置](../../registry/zookeeper/#13-配置并启用-zookeeper)

## 3 高级配置
如要开启认证鉴权,请参考 [zookeeper 注册中心 - 启用认证鉴权](../../registry/zookeeper/#31-认证与鉴权)
如要开启认证鉴权,请参考 [zookeeper 注册中心 - 启用认证鉴权](../../registry/zookeeper/#21-认证与鉴权)

### 3.1 定制外部化配置 key
**1. 启用外部化配置,并指定 key**
Expand Down Expand Up @@ -89,7 +89,7 @@ dubbo
对配置中心而言,`group``namespace` 应该是全公司(集群)统一的,应该避免不同应用使用不同的值,外部化配置和治理规则也应该存放在对应的 group 与 namespace。

## 4 流量治理规则
所有流量治理规则默认都存储在 `/dubbo/config` 节点下,具体节点结构图如下。流量治理规则的增删改建议通过 dubbo-admin 完成,更多内容可查看 Dubbo 支持的具体流量治理能力
所有流量治理规则默认都存储在 `/dubbo/config` 节点下,具体节点结构图如下。流量治理规则的增删改建议通过 dubbo-control-plane(dubbo-admin 完成,更多内容可查看 Dubbo 支持的具体流量治理能力

![zk-configcenter-governance](/imgs/user/zk-configcenter-governance.jpg)

Expand Down

0 comments on commit ebc331d

Please sign in to comment.