开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 2251|回复: 0

[教程] Springmvc整合dubbo 使用学习(dubbo开发中使用到的一些服务配...

[复制链接]

0

精华

0

贡献

0

赞扬

帖子
39
软币
193
在线时间
5 小时
注册时间
2017-7-12
发表于 2017-11-17 09:38:20 | 显示全部楼层 |阅读模式
通过之前的学习了解了dubbo的常规的使用,下面我们看看特殊情况或者说真实环境下使用dubbo的一些配置实例。
一、一个接口有多个实现时可以使用group来区分
1、服务提供者配置

[html] view plain copy


  • <?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
  •         ">      
  •      <!-- 提供方应用信息,用于计算依赖关系,这个和client没必要一致 -->  
  •     <dubbo:application name="hello-world-app-my" />  
  •      <!-- 使用zookeeper广播注册中心暴露服务地址 -->  
  •    <dubbo:registry  protocol="zookeeper"  address="192.168.0.107:2181"/>  
  •      <!-- 用dubbo协议在20880端口暴露服务 -->  
  •     <dubbo:protocol name="dubbo" port="20880" />      
  •      <!-- 声明需要暴露的服务接口 -->  
  •     <dubbo:service  group="1" interface="com.test.dubboser.ServiceDemo"  
  •         ref="demoService" />   
  •     <dubbo:service group="2" interface="com.test.dubboser.ServiceDemo"  
  •         ref="demoService2" />  
  •     <!--和本地bean一样实现服务 -->  
  •     <bean id="demoService"  class="com.test.dubboser.ServiceImp"/>  
  •     <bean id="demoService2" class="com.test.dubboser.ServiceImp2"/>  
  • </beans>  



其他的配置都是一样,而暴露的服务接口通过group来区分两个实现类

2、服务消费者配置

[html] view plain copy


  • <?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="consumer-of-helloworld-app-my" />      
  •        <!-- 使用zookeeper广播注册中心暴露发现服务地址 -->  
  •     <dubbo:registry  protocol="zookeeper"  address="192.168.0.107:2181" />      
  •     <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->   
  •     <dubbo:reference id="demoServicemy" group="1" interface="com.test.dubboser.ServiceDemo" />  
  •     <dubbo:reference id="demoServicemy2" group="2" interface="com.test.dubboser.ServiceDemo" />  
  • </beans>  


这里同样使用group来区分

二、当一个接口实现出现不兼容升级时可以用版本号过渡,版本号不同的服务互相间不引用
1、服务提供者配置

[html] view plain copy


  • <?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
  •         ">      
  •      <!-- 提供方应用信息,用于计算依赖关系,这个和client没必要一致 -->  
  •     <dubbo:application name="hello-world-app-my" />  
  •      <!-- 使用zookeeper广播注册中心暴露服务地址 -->  
  •    <dubbo:registry  protocol="zookeeper"  address="192.168.0.107:2181"/>  
  •      <!-- 用dubbo协议在20880端口暴露服务 -->  
  •     <dubbo:protocol name="dubbo" port="20880" />      
  •      <!-- 声明需要暴露的服务接口 -->  
  •     <dubbo:service  version="1" interface="com.test.dubboser.ServiceDemo"  
  •         ref="demoService" />   
  •     <dubbo:service version="2" interface="com.test.dubboser.ServiceDemo"  
  •         ref="demoService2" />  
  •     <!--和本地bean一样实现服务 -->  
  •     <bean id="demoService"  class="com.test.dubboser.ServiceImp"/>  
  •     <bean id="demoService2" class="com.test.dubboser.ServiceImp2"/>  
  • </beans>  



添加version 来区分
2、服务消费者配置

[html] view plain copy


  • <?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="consumer-of-helloworld-app-my" />      
  •        <!-- 使用zookeeper广播注册中心暴露发现服务地址 -->  
  •     <dubbo:registry  protocol="zookeeper"  address="192.168.0.107:2181" />      
  •     <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->   
  •     <dubbo:reference id="demoServicemy" version="1" interface="com.test.dubboser.ServiceDemo" />  
  •     <dubbo:reference id="demoServicemy2" version="2" interface="com.test.dubboser.ServiceDemo" />  
  • </beans>  


服务消费者这边也要使用version 来区分
经典介绍:
源码结构



愿意了解框架技术或者源码的朋友直接求求交流分享技术:2042849237
分布式的一些解决方案,有愿意了解的朋友可以找我们团队探讨
更多详细源码参考来源:http://minglisoft.cn/technology

dubbo+springmvc+mybatis+ehcache+redis J2ee分布式架构, restful, kafka, shiro



标签: dubbo+springmvc+mybatis+ehcache+redis J2ee分布式架构, restful, kafka, shiro


回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-4-27 06:13

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表