Dubbo注册中心

1 Dubbo支持多种注册中心

➢ Multicast注册中心[掌握]
➢ Zookeeper注册中心[掌握]
➢ Redis注册中心[了解]
➢ Simple注册中心[了 解]

1.1 Multicast注册中心

使用配置

<dubbo:registry address="multicast://224.5.6.7:1234" />
<dubbo:registry protocol="multicast" address="224.5.6.7:1234" />

为了减少广播量,Dubbo缺省使用单播发送提供者地址信息给消费者,如果一个机器上同时启了多个消费者进程,消费者需声明unicast=false,否则只会有一个消费者能收到消息:

<dubbo:registry address=" multicast://224.5.6.7:1234?unicast=false" />
<adubbo:registry protocol="multicast" ddress="224 5.6.7:1234">
<dubbo:parameter key="unicast" value="false" />
</dubbo:registry>

注解方式参数配置:

dubbo.registry.address=multicast://224.5.6.7:1234

1.1.1 工作原理

局域网使用哦!

  1. 提供方启动时广播自己的地址
  2. 消费方启动时广播订阅请求
  3. 提供方收到订阅请求时,单播自己的地址给订阅者,如果设置了unicast=false,则广播给订阅者
  4. 消费方收到提供方地址时,连接该地址进行RPC调用

1.1.2 特点

➢ Multicast注册中心不需要启动任何中心节点,只要组播地址一样,就可以互相发现。
➢ 组播受网络结构限制,只适合小规模应用或开发阶段使用。组播地址段: 224.0.0.0-239.255.255.255

1.2 Zookeeper注册中心

1.2.1 使用配置

  1. 在provider和consumer中增加zookeeper客户端jar包依赖:
<!--引入zookeeper服务对应版本的zookeeper jar -->
<dependency>
<groupld>org.apache.zookeeper</groupld>
<artifactld>zookeeper</artifactld>
<version>3.4.11</version>
</dependency>
  1. Dubbo支持zkclient和curator两种Zookeeper客户端实现
<dubbo:registry address="zookeeper://10.20.153.10:2181" 
	client= "zkclient" />

<dubbo:registry protocol"zookeeper" address=" 
	10.20.153.10:2181" client-"curator" />

dubbo.registry.client=zkclient

Dubbo2.6.6版本默认使用curator

  1. 使用zkclient zookeeper客户端
  2. 使用curator zookeeper客户端
<!-- 默认使用的是第三方 zookeeper 客户端 curator -->
<dependency>
	<groupld>org.apache.curator</groupld>
	<artifactld>curator- framework</artifactld>
	<version>4.2.0</version> 
	<!-- 如果您使用的zk服务版本不是3.5,请排除自动依赖,再单独引入zk依赖 -->
	<exclusions>
		<exclusion>
			<groupld>org.apache.zookeeper</groupld>
			<artifactld> zookeeper</artifactld>
		</exclusion>
	</exclusions>
</dependency>
  1. zookeepe集群配置
<dubbo:registry address= "zookeeper://10.20.153.10:2181?backup- 10.20.153.11:2181,10.20.153.12:2181" />
<dubbo:registry protocol" zookeeper" address-"10.20.153.10:2181,10.20.153.11:2181,10.20.153.12:2181" />

➢ 服务提供者启动时:向/dubbo/com.foo.BarService/providers目录下写入自己的URL地址

➢ 服务消费者启动时:订阅/dubbo/com.foo.BarService/providers目录下的提供者URL地址。
并向/dubbo/com.foo.BarService/consumers目录下写入自己的URL地址

➢ 监控中心启动时:订阅/dubbo/com.foo.BarService目录下的所有提供者和消费者URL地址。

Zookeeper注册中心支持以下功能:

➢ 当提供者出现断电等异常停机时,注册中心能自动删除提供者信息
➢ 当注册中心重启时,能自动恢复注册数据,以及订阅请求
➢ 当会话过期时,能自动恢复注册数据,以及订阅请求
➢ 当设置<dubbo:registry check=“false” />时,记录失败注册和订阅请求,后台定时重试
➢ 可通过<dubbo:registry username=" admin" password=“1234” />设置zookeeper登录信息
➢ 可通过<dubbo:registry group=“dubbo” />设置zookeeper的根节点,不设置将使用无根树
➢ 支持号通配符<dubbo:reference group="" version="*" />,可订阅服务的所有分组和所有版本的提供者

同一Zookeeper,分成多组注册中心:

<dubbo:registry id="chinaRegistry" protocol="zookeeper" address=" 10.20.153.10:2181" group="china" />
<dubbo:registry id="intlRegistry" protocol="zookeeper" address=" 10.20.153.10:2181" group="intl" /> 

特点
➢ 适合作为Dubbo服务的注册中心,工业强度较高,可用于生产环境,并推荐使用

2 支持多注册中心[了解)

Dubbo支持同一服各向多注册中心同吋注册,或者不同服努分別注册到不同的注册中心上去,
甚至可以同吋引用注册在不同注册中心上的同名服努。

向多个注册中心注册

<dubbo:application name="world" />
<!--多注册中心配置-->
<dubbo:registry id="hangzhouRegistry" address=" 10.20.141.150:9090" /> 
<dubbo:registry id="qingdaoRegistry" address-" 10.20.141.151:9010" default="false" />
<!--向多个注册中心注册-->
<dubbo:service interface="com.alibaba.hello.api.HelloService" version=" 1.0.0" ref-"helloService"
registry="hangzhouRegistry,qingdaoRegistry" >

比如:中文站有些服各来不及在青島部署,只在杭州部署,而青島的其它座用需要引用此服
各,就可以将服努同吋注册到兩个注册中心。

33 丕同服务使用不同注册中心

<dubbo:application name="world" />
<!--多注册中心配置-->
<dubbo:registry id="chinaRegistry" address=" 10.20.141.150:9090" /> 
<dubbo:registry id="intlRegistry" address="10.20.154. 177:9010" default="false" />
<!--向中文站注册中心注册-->
<dubbo:service interface="com.alibaba.hello.api.HelloService" version="1.0.0" ref="helloService"
registry="chinaRegistry" />
<!--向国际站注册中心注册-->
<dubbo:service interface="com.alibaba.hello.api.DemoService" version="1.0.0" ref="demoService"
registry="intlRegistry" />

比如: CRM有些服务是专门为国际站设计的,有些服务是专门为中文站设计的。

多注册中心引用

<dubbo:application name="world" />
<!--多注册中心配置-->
<dubbo:registry id="chinaRegistry" address=" 10.20.141.150:9090" />
<dubbo:registry id="intlRegistry" address=" 10.20.154.177:9010" default="false" />
<!--引用中文站服务-->-
<dubbo:reference id="chinaHelloService" interface="com.alibaba.hello.api.HelloService" version="1.0.0"
registry="chinaRegistry" /> 
<!--引用国际站站服务-->
<dubbo:referenfce id="intlHelloService" interface= "com.alibaba.hello.api.HelloService" version="1.0.0"
registry= "intlRegistry" />

比如: CRM需同时调用中文站和国际站的PC2服务,PC2 在中文站和国际站均有部署,接
口及版本号都一样,但连的数据库不一样。

多注册中心引用

如果只是測武坏境恪吋需要達接丙个不同注册中心,使用竪号分隔多个不同注册中心地址:

<dubbo:application name="world"
<!--多注册中心配置,竪号分隔表示同吋達接多个不同注册中心,同一-注册中心的多个集群地址用逗号分隔-->
<dubbo:registry address=" 10.20.141.150:909010.20.154.177:9010" >
<!--引用服努-->
<dubbo:reference id="helloService" interface="com.alibaba.hello.api.HelloService" version="1.0.0" />

3 支持多种使用场景[了解]

为方便开发、测试、人工管理,注册中心提供多种使用场景支持:
➢只订阅
➢只注册
➢直连提供者
➢静态服务

详细用法配置参见参考文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值