溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Dubbo多注冊中心和Zookeeper服務(wù)的遷移方法是什么

發(fā)布時間:2021-12-17 10:53:09 來源:億速云 閱讀:162 作者:iii 欄目:大數(shù)據(jù)

本篇內(nèi)容介紹了“Dubbo多注冊中心和Zookeeper服務(wù)的遷移方法是什么”的有關(guān)知識,在實(shí)際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

一、Dubbo多注冊中心

1、 應(yīng)用場景

例如阿里有些服務(wù)來不及在青島部署,只在杭州部署,而青島的其它應(yīng)用需要引用此服務(wù),就可以將服務(wù)同時注冊到兩個注冊中心。

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、不同服務(wù)使用不同注冊中心

比如:CRM有些服務(wù)是專門為國際站設(shè)計的,有些服務(wù)是專門為中文站設(shè)計的。

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需同時調(diào)用中文站和國際站的PC2服務(wù),PC2在中文站和國際站均有部署,接口及版本號都一樣,但連的數(shù)據(jù)庫不一樣。

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

    <!-- 引用中文站服務(wù) -->  

    <dubbo:reference id="chinaHelloService" interface="com.alibaba.hello.api.HelloService" version="1.0.0" registry="chinaRegistry" />  

    <!-- 引用國際站站服務(wù) -->  

    <dubbo:reference id="intlHelloService" interface="com.alibaba.hello.api.HelloService" version="1.0.0" registry="intlRegistry" />  

</beans>  

consumer.xml如果只是測試環(huán)境臨時需要連接兩個不同注冊中心,使用豎號分隔多個不同注冊中心地址:

<?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" />  

    <!-- 引用服務(wù) -->  

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

</beans>  

二、Dubbo多注冊中心的服務(wù)遷移

1、顧名思義,將服務(wù)從一個地兒遷到另一個地兒,例如從A地遷到B地。

2、如何實(shí)現(xiàn)多注冊中心的服務(wù)遷移

步驟一

     添加B地的注冊中心地址,AB兩地的注冊中心間用英文的|分割,(同一個服務(wù)集群的zk節(jié)點(diǎn)使用逗號分割)

     例如: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重新構(gòu)建服務(wù),zk1本身就是含有全部服務(wù)的,現(xiàn)在構(gòu)建是將服務(wù)部署到zk2集群中。這樣就可實(shí)現(xiàn)A的zk和B地的zk兩套注冊中心享有兩套相同的服務(wù)

步驟三

     把服務(wù)的消費(fèi)端都構(gòu)建一遍;

步驟四

     先取消服務(wù)消費(fèi)者調(diào)用zk1的服務(wù),具體實(shí)施就是去掉第一個zk的配置,然后構(gòu)建消費(fèi)者

步驟五

     把服務(wù)提供者的配置也取消;然后重新構(gòu)建服務(wù)提供者。這樣就完成了將zk1中的所有服務(wù)遷移到zk2中,且去除zk1中的所有服務(wù)。

“Dubbo多注冊中心和Zookeeper服務(wù)的遷移方法是什么”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI