spring dubbo 配置,项目中连接多个注册中心

 

如果项目需要连接多个ZooKeeper,则定义多个dubbo:registry,对应的dubbo:reference与dubbo:service指定的注册中心registry="registry1"。

   

 

<?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:context="http://www.springframework.org/schema/context"
       xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
       http://code.alibabatech.com/schema/dubbo 
       http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <context:property-placeholder location="classpath*:config/dubbo.properties" ignore-unresolvable="true" />

   <!-- 提供方应用名称信息,这个相当于起一个名字,我们dubbo管理页面比较清晰是哪个应用暴露出来的 -->
    <dubbo:application name="${system.dubbo.application}"/>

    <!-- 使用zookeeper注册中心暴露服务地址 -->
    <dubbo:registry id="registry1" address="${system.dubbo.registry1}" check="false"/>
    <dubbo:registry id="registry2" address="${system.dubbo.registry2}" check="false"/>
    
    <!-- 用dubbo协议在20880端口暴露服务 -->
    <dubbo:protocol name="dubbo" port="20880" />

    <dubbo:consumer check="false" timeout="20000" />

    <!-- 要引用的服务 -->
    <dubbo:reference id="interface1" registry="registry1"
        interface="com.*.*.Interface1" timeout="12000" check="false" />
    <dubbo:reference id="interface2" registry="registry2"
        interface="com.*.*.Interface2" timeout="12000" check="false" />
    <!-- 要暴露的服务接口 -->
    <dubbo:service registry="registry1" interface="com.dubbo.service.IfinancePDLGateway"
        ref="ifinancePDLGatewayImpl" timeout="12000" />
    
</beans>

 

     

system.dubbo.application = ${system.dubbo.application}
system.dubbo.registry1= ${system.dubbo.registry1}
system.dubbo.registry2= ${system.dubbo.registry2}

dubbo.reference.check = false

 

 配置文件中的${},请看  maven多环境配置打包

 

system.dubbo.application = ***_dev_service
system.dubbo.registry1= zookeeper://192.168.0.81:2181
system.dubbo.registry2= zookeeper://192.168.0.82:2181

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值