springboot+dubbo分组+zookeeper集群

springboot+dubbo分组+zookeeper集群

provider

修改注册中心服务地址为多个

<dubbo:registry protocol="zookeeper" address="192.168.73.211:2181,192.168.73.212:2181,192.168.73.213:2181" />

同一接口有多个实现使用group区分
同一接口出现版本不兼容升级使用version过度

<dubbo:service interface="com.example.demo.service.DemoService" ref="demoService" group="afternoon" version="1.0.0"/>

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="dubbo-provider" />

    <!-- zookeeper注册中心的服务地址 -->
    <dubbo:registry protocol="zookeeper" address="192.168.73.211:2181,192.168.73.212:2181,192.168.73.213:2181" />

    <!-- 用dubbo协议在20880端口暴露服务,协议通信端口 -->
    <dubbo:protocol name="dubbo" port="20880" />

    <!-- 用户服务接口 -->
    <dubbo:service interface="com.example.demo.service.DemoService" ref="demoService" group="afternoon" version="1.0.0"/>
    <dubbo:service interface="com.example.demo.service.DemoService" ref="demoService2" group="morning" version="2.0.0"/>

    <!-- 用户服务接口实现 -->
    <bean id="demoService" class="com.example.demo.service.impl.DemoServiceImpl"/>
    <bean id="demoService2" class="com.example.demo.service.impl.DemoServiceImpl2"/>
</beans>

consumer

修改注册中心地址为多个

<dubbo:registry protocol="zookeeper" address="192.168.73.211:2181,192.168.73.212:2181,192.168.73.213:2181" />

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"
       xmlns:context="http://www.springframework.org/schema/context" 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 http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
    <!-- 服务名 -->`在这里插入代码片`
    <dubbo:application name="demo-consumer" />
    <!-- zookeeper注册中心暴露服务地址 -->
    <dubbo:registry protocol="zookeeper" address="192.168.73.211:2181,192.168.73.212:2181,192.168.73.213:2181" />
    <!-- 用户服务接口 -->
    <dubbo:reference id="demoService" interface="com.example.demo.service.DemoService" />

    <dubbo:annotation package="com.example.demo.controller" />

    <!-- 把标记了@Controller注解的类转换为bean -->
    <context:component-scan base-package="com.example.demo.controller" />
</beans>

注意:
@Reference引用服务加上group、version

    //用dubbo的@Reference注解去连接提供者提供服务
    @Reference(group = "morning",version = "2.0.0")
    private DemoService demoService;
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值