Dubbo中多注册中心问题与服务分组

一:注册中心

1.场景

  Dubbo 支持同一服务向多注册中心同时注册,

  或者不同服务分别注册到不同的注册中心上去,

  甚至可以同时引用注册在不同注册中心上的同名服务。

 

2.多注册中心注册

  中文站有些服务来不及在青岛部署,只在杭州部署,而青岛的其它应用需要引用此服务,就可以将服务同时注册到两个注册中心

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
 5     xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/dubbo.xsd">
 6     <dubbo:application name="world"  />
 7     <!-- 多注册中心配置 -->
 8     <dubbo:registry id="hangzhouRegistry" address="10.20.141.150:9090" />
 9     <dubbo:registry id="qingdaoRegistry" address="10.20.141.151:9010" default="false" />
10     <!-- 向多个注册中心注册 -->
11     <dubbo:service interface="com.alibaba.hello.api.HelloService" version="1.0.0" ref="helloService" registry="hangzhouRegistry,qingdaoRegistry" />
12 </beans>

 

3.不同服务使用不同注册中心

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

 1 <beans xmlns="http://www.springframework.org/schema/beans"
 2     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3     xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
 4     xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/dubbo.xsd">
 5     <dubbo:application name="world"  />
 6     <!-- 多注册中心配置 -->
 7     <dubbo:registry id="chinaRegistry" address="10.20.141.150:9090" />
 8     <dubbo:registry id="intlRegistry" address="10.20.154.177:9010" default="false" />
 9     <!-- 向中文站注册中心注册 -->
10     <dubbo:service interface="com.alibaba.hello.api.HelloService" version="1.0.0" ref="helloService" registry="chinaRegistry" />
11     <!-- 向国际站注册中心注册 -->
12     <dubbo:service interface="com.alibaba.hello.api.DemoService" version="1.0.0" ref="demoService" registry="intlRegistry" />
13 </beans>

 

4.多注册中心引用

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

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
 5     xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/dubbo.xsd">
 6     <dubbo:application name="world"  />
 7     <!-- 多注册中心配置 -->
 8     <dubbo:registry id="chinaRegistry" address="10.20.141.150:9090" />
 9     <dubbo:registry id="intlRegistry" address="10.20.154.177:9010" default="false" />
10     <!-- 引用中文站服务 -->
11     <dubbo:reference id="chinaHelloService" interface="com.alibaba.hello.api.HelloService" version="1.0.0" registry="chinaRegistry" />
12     <!-- 引用国际站站服务 -->
13     <dubbo:reference id="intlHelloService" interface="com.alibaba.hello.api.HelloService" version="1.0.0" registry="intlRegistry" />
14 </beans>

 

二:服务分组

1.场景

  当一个接口有多种实现时,可以用 group 区分。

 

2.服务

  这里的ref属性没写。如果写上ref就可以表明每个组里有哪些实现了。

  <dubbo:service group="feedback" interface="com.xxx.IndexService" />   <dubbo:service group="member" interface="com.xxx.IndexService" />

 

3.引用

  <dubbo:reference id="feedbackIndexService" group="feedback" interface="com.xxx.IndexService" />   <dubbo:reference id="memberIndexService" group="member" interface="com.xxx.IndewxService" />
任意组:
  <dubbo:reference id="barService" interface="com.foo.BarService" group="*" />

 

转载于:https://www.cnblogs.com/juncaoit/p/7693262.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值