dubbo开发中使用到的一些服务配置方式
通过之前的学习了解了dubbo的常规的使用,下面我们看看特殊情况或者说真实环境下使用dubbo的一些配置实例。
一、一个接口有多个实现时可以使用group来区分
1、服务提供者配置
- <?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、服务消费者配置
- <?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、服务提供者配置
- <?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、服务消费者配置
- <?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 来区分
三、点对点直连/指定调用需求(一般在开发测试环境中使用)
点对点直连的话我们就没必要使用zookeeper来做注册中心了,直接启动服务提供者而服务消费者直接调用指定的服务消费者接口实现类方法,所以注意这里的配置方式
1、服务提供者配置
- <?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" />
- <!--没有将服务注册到注册中心 -->
- <dubbo:registry address="N/A" />
- <!-- 用dubbo协议在20880端口暴露服务 -->
- <dubbo:protocol name="dubbo" port="20880" />
- <!-- 声明需要暴露的服务接口 -->
- <dubbo:service interface="com.test.dubboser.ServiceDemo"
- ref="demoService" />
- <!--和本地bean一样实现服务 -->
- <bean id="demoService" class="com.test.dubboser.ServiceImp"/>
- </beans>
2、服务消费者配置
- <?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" />
- <!--没有注册到注册中心 -->
- <dubbo:registry address="N/A" ></dubbo:registry>
- <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
- <dubbo:reference id="demoServicemy" interface="com.test.dubboser.ServiceDemo" url="dubbo://192.168.0.107:20880/com.test.dubboser.ServiceDemo"/>
- </beans>
点对点的访问url 就是服务端的ip:port/接口全路径,也就是上面配置文件所示!
四、只订阅,共用注册中心,开发人员机器上的服务提供者被吴调用,影响其他开发人员
为方便开发测试,经常会在线下共用一个所有服务可用的注册中心,这时,如果一个正在开发中的服务提供者注册,可能会影响消费者不能正常运行。
以让服务提供者开发方,只订阅服务(开发的服务可能依赖其它服务),而不注册正在开发的服务,通过直连测试正在开发的服务。
1、服务提供者配置
- <?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" />
- <!-- 不注册-->
- <dubbo:registry protocol="zookeeper" address="192.168.0.107:2181" register="false"/>
- <!-- 用dubbo协议在20880端口暴露服务 -->
- <dubbo:protocol name="dubbo" port="20880" />
- <!-- 声明需要暴露的服务接口 -->
- <dubbo:service interface="com.test.dubboser.ServiceDemo"
- ref="demoService" />
- <!--和本地bean一样实现服务 -->
- <bean id="demoService" class="com.test.dubboser.ServiceImp"/>
- </beans>
注意这里在想注册中心注册的时候有register="false" 所以服务提供者没有向服务注册中心注册服务,也就是没有暴露服务接口等信息
2、服务消费者配置
- <?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" />
- <!-- 还是使用点对点的方式访问,因为服务提供者没有向注册中心注册 -->
- <dubbo:reference id="demoServicemy3" interface="com.test.dubboser.ServiceDemo" url="dubbo://192.168.0.107:20880/com.test.dubboser.ServiceDemo" />
- </beans>
服务消费者还是使用了点对点的方法方式来访问
只订阅模式的图形:
ok 这篇文章到此就结束了,这篇文章中没有给出java相关的代码是因为那些和之前的都一样的而把这些比较实用而且在开发中确实能遇到的配置在这里贴出来备份以后使用,当然了这些配置都测试过,都是可以使用!
dubbo开发中使用到的一些服务配置方式的更多相关文章
- 怎样在Android开发中FPS游戏实现的两种方式比较
怎样在Android开发中FPS游戏实现的两种方式比较 如何用Android平台开发FPS游戏,其实现过程有哪些方法,这些方法又有哪些不同的地方呢?首先让我们先了解下什么是FPS 英文名:FPS (F ...
- Spring3.2 中 Bean 定义之基于 XML 配置方式的源码解析
Spring3.2 中 Bean 定义之基于 XML 配置方式的源码解析 本文简要介绍了基于 Spring 的 web project 的启动流程,详细分析了 Spring 框架将开发人员基于 XML ...
- Log4j 2.0在开发中的高级使用具体解释—配置简单的控制台输出(三)
Log4j 2.0在近期迎来了重大的版本号升级.攻克了1.x中死锁bug之外,性能也有10倍的提升. 相同的在最新版本号中的新特性中. 配置文件也不只局限于xml和java特性文件properties ...
- iOS开发中方法延迟执行的几种方式
概述 项目开发中经常会用到方法的延时调用,下面列举常用的几种实现方式: 1.performSelector 2.NSTimer 3.NSThread线程的sleep 4.GCD 1.performSe ...
- Android开发中常用的ListView列表的优化方式ViewHolder
在Android开发中难免会遇到大量的数据加载到ListView中进行显示, 然后其中最重要的数据传递桥梁Adapter适配器是常用的,随着市场的需 求变化ListView'条目中的内容是越来越多这就 ...
- spring 中常用的两种事务配置方式以及事务的传播性、隔离级别
一.注解式事务 1.注解式事务在平时的开发中使用的挺多,工作的两个公司中看到很多项目使用了这种方式,下面看看具体的配置demo. 2.事务配置实例 (1).spring+mybatis 事务配置 &l ...
- centos中selinux功能及常用服务配置
SELinux: Secure Enhenced Linux 常用命令 获取selinux的当前状态: # getenforce 临时启用或禁用: # setenfoce 0|1 永久性启用,需要修改 ...
- 浅谈iOS开发中方法延迟执行的几种方式
Method1. performSelector方法 Method2. NSTimer定时器 Method3. NSThread线程的sleep Method4. GCD 公用延迟执行方法 - (vo ...
- iOS开发中数组常用的五种遍历方式
随着iOS的不断发展,apple也不断推出性能更高的数组遍历方式,下面将对熟悉的五种遍历方式进行列举. 首先定义一个数组,并获取数组长度 NSArray *array=@[",]; NSIn ...
随机推荐
- 熊猫猪新系统測试之四:Ubuntu 14.04
眼下猫猪在办公室一般用的就是乌班图系统,一方面原因是老本本性能跑不起来Windows,更重要的是本猫认为Linux系统更开放些.况且如今用的也比較熟了,全然能够脱离Windows鸟!这一系列4篇新系统 ...
- 倍福TwinCAT(贝福Beckhoff)基础教程5.1 TwinCAT如何执行系统命令
TwinCAT提供了一系列的执行Windows系统命令的方法 Name 描述 NT_Shutdown 关机操作系统 NT_AbortShutdown 取消关机操作系统命令 NT_Reboot 重启操作 ...
- JAVA经常使用集合框架使用方法具体解释基础篇二之Colletion子接口List
接着上一篇,接着讲讲集合的知识.上一篇讲了Collection接口.它能够说是集合的祖先了,我们这一篇就说说它的子孙们. 一.Collection的子接口 List:有序(存入和取出的顺序一致).元素 ...
- DNS检测
dig @58.241.41.152 6900255264940.barcode.cniotroot.cn naptr 没有naptr 好像有点异常 select count(*) as total ...
- js原生方式实现bind方法
1.思路 (1)因为bind方法不会立即执行函数,需要返回一个待执行的函数(这里用到闭包,可以返回一个函数)return function(){} (2)作用域绑定,这里可以使用apply或者call ...
- STL学习笔记(迭代器类型)
迭代器类型 迭代器是一种“能够遍历某个序列内的所有元素”的对象.它可以透过与一般指针一致的接口来完成自己的工作. 不同的迭代器具有不同的”能力“(行进和存取能力) Input迭代器 Input迭代器只 ...
- Oracle 删除用户和表空间------创建表空间和用户
步骤一: 删除user drop user ×× cascade 说明: 删除了user,只是删除了该user下的schema objects,是不会删除相应的tablespace的. 步骤二: 删 ...
- WebService的缓存机制
分类: .NET ASP 2010-11-13 10:00 849人阅读 评论(0) 收藏 举报 webservicestring数据库nullapplicationweb服务 WebService的 ...
- SQL 根据表获取字段字符串
SQLSERVER查询单个数据表所有字段名组合成的字符串脚本 --SQLSERVER查询单个数据表所有字段名组合成的字符串脚本 --应用场合: 用于生成SQL查询字符串中select 字段名列表1 f ...
- LINQ使用与并行
LINQ介绍 參考:https://msdn.microsoft.com/en-us/library/bb397906.aspx LINQ查询主要运行操作包含:1)获取数据源:2)创建查询:3)运行查 ...