Dubbo Multi-Registration Center

 

(1) Multi-registry registration

 

Requirements: Some services of xx bank are too late to be deployed in Shanghai, but only in Beijing. Other applications in Shanghai need to refer to this service, and the services can be registered in two registration centers at the same time.

 

consumer.xml

 

<?xmlversion="1.0"encoding="UTF-8"?>

<beansxmlns=" 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/beans

         http://www.springframework.org/schema/beans/spring-beans.xsd

         http://code.alibabatech.com/schema/dubbo

         http://code.alibabatech.com/schema/dubbo/dubbo.xsd

        ">

 

    <dubbo:applicationname="world"/>

 

    <!-- Multi-registry configuration-->

    <dubbo:registryid="beijingRegistry"address="10.20.141.150:9090"/>

    <dubbo:registryid="shanghaiRegistry"address="10.20.141.151:9010"default="false"/>

 

    <!-- Register with multiple registries-->

   <dubbo:serviceinterface="com.alibaba.hello.api.HelloService"version="1.0.0"ref="helloService"registry="beijingRegistry,shanghaiRegistry"/>

 

</beans>

 

          The above work is to expand the registration center , register with multiple registration centers , and register the services of HelloService to the registration centers in Shanghai and Beijing at the same time.

 

(2) Different services use different registries

 

Demand: Some services of xx bank are specially designed for foreign countries, and some services are specially designed for domestic purposes.

 

consumer.xml

 

<?xmlversion="1.0"encoding="UTF-8"?>

<beansxmlns=" 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/beans

         http://www.springframework.org/schema/beans/spring-beans.xsd

         http://code.alibabatech.com/schema/dubbo

         http://code.alibabatech.com/schema/dubbo/dubbo.xsd

        ">

 

    <dubbo:applicationname="world"/>

 

    <!-- 多注册中心配置 -->

   <dubbo:registryid="chinaRegistry"address="10.20.141.150:9090"/>

   <dubbo:registryid="intlRegistry"address="10.20.154.177:9010"default="false"/>

 

    <!-- 向国内注册中心注册 -->

   <dubbo:serviceinterface="com.alibaba.hello.api.HelloService"version="1.0.0"ref="helloService"registry="chinaRegistry"/>

 

    <!-- 向国外注册中心注册 -->

   <dubbo:serviceinterface="com.alibaba.hello.api.DemoService"version="1.0.0"ref="demoService"registry="intlRegistry"/>

 

</beans>

 

        不同服务使用不同注册中心是注册中心扩展的第二个需求,当然这个内容对于开发者而言非常有用,尤其是在本地调试进行开发的时候一些服务是我本地所不能提供的,这时候这种需求就需要我们扩展注册中心.

 

(3) 多注册中心引用

 

需求:xx银行需同时调用国内和国外的xxx服务,xxx服务在中文站和国际站均有部署,接口及版本号都一样,但连的数据库不一样。

 

consumer.xml

 

<?xmlversion="1.0"encoding="UTF-8"?>

<beansxmlns=" 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/beans

         http://www.springframework.org/schema/beans/spring-beans.xsd

         http://code.alibabatech.com/schema/dubbo

         http://code.alibabatech.com/schema/dubbo/dubbo.xsd

        ">

 

    <dubbo:applicationname="world"/>

 

    <!-- 多注册中心配置 -->

   <dubbo:registryid="chinaRegistry"address="10.20.141.150:9090"/>

   <dubbo:registryid="intlRegistry"address="10.20.154.177:9010"default="false"/>

 

    <!-- 引用中文站服务 -->

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

 

    <!-- 引用国际站站服务 -->

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

 

</beans>

 

 

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

 

consumer.xml

 

<?xmlversion="1.0"encoding="UTF-8"?>

<beansxmlns=" 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/beans

         http://www.springframework.org/schema/beans/spring-beans.xsd

         http://code.alibabatech.com/schema/dubbo

         http://code.alibabatech.com/schema/dubbo/dubbo.xsd

        ">

 

    <dubbo:applicationname="world"/>

 

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

   <dubbo:registryaddress="10.20.141.150:9090|10.20.154.177:9010"/>

 

    <!-- 引用服务 -->

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

 

</beans>

 

 

         通过对扩展注册中心和扩展协议的了解,dubbo本身还是非常灵活的.当然,这里的协议和注册中心只是它多个可扩展内容的一部分.它还具有集群扩展,线程池扩展,缓存扩展,容器扩展等等丰富的扩展内容.其他的扩展内容我在项目中还未实际用到.或许会在以后更为特殊的需求上面用到他们.

 
转自:http://blog.csdn.net/jnqqls/article/details/46279523 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326561516&siteId=291194637