天天看点

Dubbo注册中心(下)2 支持多注册中心[了解)3 支持多种使用场景[了解]

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 支持多种使用场景[了解]

为方便开发、测试、人工管理,注册中心提供多种使用场景支持:

➢只订阅

➢只注册

➢直连提供者

➢静态服务

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