配置中心

提示

Dubbo 动态配置中心仅适用于北极星服务端版本 >= 1.18.0

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 中引入以下依赖

<!-- 北极星注册发现插件 -->
<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>
<!-- 北极星动态配置中心插件 -->
<dependency>
    <groupId>com.tencent.polaris</groupId>
    <artifactId>dubbo-configcenter-polaris</artifactId>
    <version>${revision}</version>
</dependency>

参数配置

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

配置文件方式添加:

dubbo.registry.address=polaris://127.0.0.1:8091
dubbo.metadata-report.address=polaris://127.0.0.1:8091
dubbo.config-center.address=polaris://127.0.0.1:8093

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

参数 类型 含义
namespace string 指定服务的命名空间
token string 指定用户token
persist_enable bool 设置是否开启客户端本地文件容灾缓存
stat_type string 设置监控数据上报方式, pull 或者 push
stat_pull_port int stat_type == pull 时,设置 SDK 额外暴露的 metrics web 端口
stat_push_addr string stat_type == push 时,设置 pushgateway 的 IP:PORT 地址
stat_push_interval int stat_type == push 时,设置上报周期,单位为毫秒
config_port int 设置北极星配置中心链接端口,默认为8093
discover_port int 设置北极星注册中心链接端口,默认为8091

验证

服务注册样例可以参考:dubbo-discovery-provider

这里我们已 dubbo 本身的 QOS 能力开关做一个示范, 这里我们现在北极星创建一个控制 dubbo QOS 能力的配置

  • 北极星配置分组名为 dubbo application name
  • dubbo 默认会给配置中心的接入地址填充 namespace 信息为 dubbo

未在配置中心发布 Dubbo 配置

我们在启动 dubbo 应用之后,可以观察到 dubbo 开启了 qos-server

12:36:50.117 |-INFO  [main]       org.apache.dubbo.qos.server.Server:123 -|  [DUBBO] qos-server bind localhost:22222, dubbo version: 3.2.6, current host: 10.21.22.75

在配置中心发布 Dubbo 配置

我们在启动 dubbo 应用之后,可以观察到 dubbo 在启动过程中, 从北极星配置中心读取到到了 dubbo.application.qos-enable=false 配置,因此不会启动 dubbo 内置的 qos-server

15:26:03.571 |-INFO  [main] he.dubbo.qos.protocol.QosProtocolWrapper:109 -|  [DUBBO] qos won't be started because it is disabled. 
Please check dubbo.application.qos.enable is configured either in system property, dubbo.properties or XML/spring-boot configuration., dubbo version: 3.2.6, current host: 10.21.22.75