首页 技术 正文
技术 2022年11月15日
0 收藏 373 点赞 2,280 浏览 3982 个字

一、Dubbo多注册中心

1、 应用场景

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

consumer.xml

<?xml version=”1.0″ encoding=”UTF-8″?>

<beans xmlns=”http://www.springframework.org/schema/beans”

xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”

xmlns:dubbo=”http://code.alibabatech.com/schema/dubbo”

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

<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” />

</beans>

2、不同服务使用不同注册中心

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

consumer.xml

<?xml version=”1.0″ encoding=”UTF-8″?>

<beans xmlns=”http://www.springframework.org/schema/beans”

xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”

xmlns:dubbo=”http://code.alibabatech.com/schema/dubbo”

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

<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” />

</beans>

3、多注册中心引用

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

consumer.xml

<?xml version=”1.0″ encoding=”UTF-8″?>

<beans xmlns=”http://www.springframework.org/schema/beans”

xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”

xmlns:dubbo=”http://code.alibabatech.com/schema/dubbo”

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

<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:reference id=”intlHelloService” interface=”com.alibaba.hello.api.HelloService” version=”1.0.0″ registry=”intlRegistry” />

</beans>

consumer.xml如果只是测试环境临时需要连接两个不同注册中心,使用竖号分隔多个不同注册中心地址:

<?xml version=”1.0″ encoding=”UTF-8″?>

<beans xmlns=”http://www.springframework.org/schema/beans”

xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”

xmlns:dubbo=”http://code.alibabatech.com/schema/dubbo”

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

<dubbo:application name=”world”  />

<!– 多注册中心配置,竖号分隔表示同时连接多个不同注册中心,同一注册中心的多个集群地址用逗号分隔 –>

<dubbo:registry address=”10.20.141.150:9090|10.20.154.177:9010″ />

<!– 引用服务 –>

<dubbo:reference id=”helloService” interface=”com.alibaba.hello.api.HelloService” version=”1.0.0″ />

</beans>

二、Dubbo多注册中心的服务迁移

1、顾名思义,将服务从一个地儿迁到另一个地儿,例如从A地迁到B地。

2、如何实现多注册中心的服务迁移

步骤一

添加B地的注册中心地址,AB两地的注册中心间用英文的|分割,(同一个服务集群的zk节点使用逗号分割)

例如:dubbo.registry.address=192.168.220.128:2181|192.168.221.129:2181,192.168.221.130:2181,192.168.221.131:2181 这就是两个注册中心配置sample

步骤二

Jenkins重新构建服务,zk1本身就是含有全部服务的,现在构建是将服务部署到zk2集群中。这样就可实现A的zk和B地的zk两套注册中心享有两套相同的服务

步骤三

把服务的消费端都构建一遍;

步骤四

先取消服务消费者调用zk1的服务,具体实施就是去掉第一个zk的配置,然后构建消费者

步骤五

把服务提供者的配置也取消;然后重新构建服务提供者。这样就完成了将zk1中的所有服务迁移到zk2中,且去除zk1中的所有服务。

Dubbo多注册中心和Zookeeper服务的迁移

海量视频获取  vue  angular  spring dubbo

Dubbo多注册中心和Zookeeper服务的迁移

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,992
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,767
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844