服务注册

Dubbo 分类

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

Apache Dubbo 接入

支持版本

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

引入依赖

<p class="notice-title">
    <span class="icon-notice baseline">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="300.5 134 300 300">
    </span>提示</p><p>Dubbo 应用级注册发现 仅适用于北极星服务端版本 &gt;= 1.18.0</p></div>

在 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>

在 pom.xml 中引入以下依赖

<!-- 北极星注册发现插件 -->
<dependency>
      <groupId>com.tencent.polaris</groupId>
      <artifactId>dubbo-registry-polaris</artifactId>
      <version>${version}</version>
</dependency>

参数配置

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

配置文件方式添加:

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

dubbo.registry.address=polaris://127.0.0.1:8091

北极星地址的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

结果验证

服务注册样例可以参考: