zoukankan      html  css  js  c++  java
  • Dubbo -- 系统学习 笔记 -- 示例 -- 多注册中心

    Dubbo -- 系统学习 笔记 -- 目录

    示例

      想完整的运行起来,请参见:快速启动,这里只列出各种场景的配置方式

    多注册中心

    可以自行扩展注册中心,参见:注册中心扩展

    (1) 多注册中心注册

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

      XML : provider.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/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: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有些服务是专门为国际站设计的,有些服务是专门为中文站设计的。

      XML : provider.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/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: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在中文站和国际站均有部署,接口及版本号都一样,但连的数据库不一样。

      XML : 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/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: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>

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

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

    啦啦啦

  • 相关阅读:
    2012年6月30号PMP考试总结
    安装了VS2010 sp1 后再安装ASP.NET MVC 3.0的问题(Final Result: Installation failed with error code: (0x80070643), "安装时发生严重错误 " (Ela)
    黄光裕方面独家点评国美中报:领先优势即将丧失
    Asp.net 模板页(MasterPage)里的 js脚本路径
    Windows 7 Sp1 x64 无法安装英文语言包(已解决)
    The issue of vertical lines throughing the Report footer or the whole page in Crystal report 11
    Windows Server 2008 R2 with Service Pack 1
    垃圾农业银行网银https://www.95599.cn/PersonalBank/startUpHtmlSessionAction.ebf
    如何填写PMP审计表单,Audit注意事项
    被日军飞机炸毁的上海南火车站铁轨上拍摄了一个父母刚被炸死、正在铁轨上深哀啼号的婴儿
  • 原文地址:https://www.cnblogs.com/ClassNotFoundException/p/6978850.html
Copyright © 2011-2022 走看看