亚洲视频二区_亚洲欧洲日本天天堂在线观看_日韩一区二区在线观看_中文字幕不卡一区

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.430618.com 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

概述

Dubbo支持同一服務向多個注冊中心同時注冊,或者不同服務分別注冊到不同的注冊中心上去,甚至可以同時引用注冊在不同注冊中心上的同名服務。另外,注冊中心是也支持自定義擴展。

多注冊中心注冊

首先dubbo:registry定義多個注冊中心,每個注冊中心使用id作為唯一標識;然后曝露服務時,在dubbo:service的registry屬性上引用要注冊的注冊中心,多個注冊中心id使用逗號分隔

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://dubbo.Apache.org/schema/dubbo"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">

    <!-- 服務提供方應用名稱,方便用于依賴跟蹤,另外,指定使用slf4j日志-->
    <dubbo:Application name="coffee-operation-center" logger="slf4j"/>

    <!-- 聲明華南、華中、華北三個注冊中心 -->
    <dubbo:registry id="huananRegistry" address="zookeeper://192.168.8.156:2181"/>
    <dubbo:registry id="huazhongRegistry" address="zookeeper://192.168.8.157:2181" default="false"/>
    <dubbo:registry id="huabeiRegistry" address="zookeeper://192.168.8.158:2181" default="false"/>

    <!-- 聲明orderService的實現bean -->
    <bean id="orderService" class="com.fandou.coffee.order.service.OrderServiceImpl" />
    <!-- 曝露訂單服務:注冊到三個注冊中心 -->
    <dubbo:service registry="huananRegistry,huazhongRegistry,huabeiRegistry" interface="com.fandou.coffee.api.order.OrderService" ref="orderService"/>
</beans>

不同服務注冊到不同注冊中心

比如支付服務,在不同的國家地區,可能使用不同的支付服務,有些支付服務可以跨國家地區,有些只能在本地區使用

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">

    <!-- 服務提供方應用名稱,方便用于依賴跟蹤,另外,指定使用slf4j日志-->
    <dubbo:application name="coffee-operation-center" logger="slf4j"/>

    <!-- 聲明美洲、亞洲、歐洲三個注冊中心 -->
    <dubbo:registry id="americaRegistry" address="zookeeper://192.168.8.156:2181"/>
    <dubbo:registry id="asiaRegistry" address="zookeeper://192.168.8.157:2181" default="false"/>
    <dubbo:registry id="europeRegistry" address="zookeeper://192.168.8.158:2181" default="false"/>

    <!-- 多種在線支付服務 -->
    <bean id="weChatPayService" class="com.fandou.coffee.pay.service.WeChatPayServiceImpl" />
    <bean id="aliPayService" class="com.fandou.coffee.pay.service.AliPayServiceImpl" />
    <bean id="applePayService" class="com.fandou.coffee.pay.service.ApplePayServiceImpl" />
    <bean id="paypalPayService" class="com.fandou.coffee.pay.service.PaypalPayServiceImpl" />

    <!-- 微信、支付寶在亞洲注冊中心,paypal在美洲和歐洲注冊中心,applePay注冊到全部注冊中心-->
    <dubbo:service registry="asiaRegistry" group="pay.wechat" interface="com.fandou.coffee.api.pay.PayService" ref="weChatPayService"/>
    <dubbo:service registry="asiaRegistry" group="pay.ali" interface="com.fandou.coffee.api.pay.PayService" ref="aliPayService"/>
    <dubbo:service registry="americaRegistry,asiaRegistry,europeRegistry" group="pay.apply" interface="com.fandou.coffee.api.pay.PayService" ref="applePayService"/>

    <dubbo:service registry="americaRegistry,europeRegistry" group="pay.paypal" interface="com.fandou.coffee.api.pay.PayService" ref="paypalPayService"/>
</beans>

多注冊中心引用

對于服務消費者方,需要用到哪個注冊中心,就聲明哪個注冊中心,無需將全部注冊中心進行聲明。引用服務的時候,按需引用即可。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">

    <!-- 服務消費方應用名稱,方便用于依賴跟蹤 -->
    <dubbo:application name="coffee-user-center" logger="slf4j">
        <dubbo:parameter key="qos.enable" value="true" />
        <dubbo:parameter key="qos.accept.foreign.ip" value="false" />
        <dubbo:parameter key="qos.port" value="33333" />
    </dubbo:application>

    <!-- 用到歐洲和亞洲兩個注冊中心 -->
    <dubbo:registry id="asiaRegistry" address="zookeeper://192.168.8.157:2181"/>
    <dubbo:registry id="europeRegistry" address="zookeeper://192.168.8.158:2181" default="false"/>

    <dubbo:protocol name="dubbo" port="20881"/>
    
    <!-- 不同的支付服務引用從不同的注冊中心中引用 -->
    <dubbo:reference registry="asiaRegistry"  id="weChatPayService" group="pay.wechat" interface="com.fandou.coffee.api.pay.PayService" check="false" />
    <dubbo:reference registry="asiaRegistry"  id="aliPayService" group="pay.ali" interface="com.fandou.coffee.api.pay.PayService" check="false" />
    <dubbo:reference registry="europeRegistry"  id="applyPayService" group="pay.apply" interface="com.fandou.coffee.api.pay.PayService" check="false" />
</beans>

總結

在Dubbo中,一個服務可以向多個注冊中心同時注冊,不同服務可以分別注冊到不同的注冊中心上去。

Dubbo高級特性應用之多注冊中心

dubbo的多注冊中心應用

分享到:
標簽:Dubbo
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定