Dubbo多注冊中心和Zookeeper服務的遷移


一、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中的所有服務。

 

海量視頻獲取  vue  angular  spring dubbo


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM