dubbo 使用学习六(多协议,多注册中心配置)
2016-10-28 00:50
591 查看
一、不同服务在性能上适用不同协议进行传输,大数据使用短连接,小数据大并发使用长链接协议
1、服务提供者配置
从这些配置我们看到,不同服务使用不同的协议,这种配置方式和其他的配置方式是一样的哦 哈哈……
2、服务消费者配置
消费端还是按照正常方式获取服务,只是传递使用的协议不同,底层tcp链接时常不同……
二、同一服务多协议配置
1、服务提供者配置
2、服务消费者配置
三、不同服务注册到不同的注册中心
1、服务提供者配置
2、服务消费者配置文件
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.101:2181"/> <!-- 用dubbo协议在20880端口暴露服务 --> <dubbo:protocol name="dubbo" port="20880" /> <!-- 用rmi协议在20881端口暴露服务 --> <dubbo:protocol name="rmi" port="20881" /> <!-- 声明需要暴露的服务接口 --> <dubbo:service interface="com.test.dubboser.ServiceDemo" ref="demoService" protocol="dubbo" /> <dubbo:service interface="com.test.dubboser.ServiceDemo2" ref="demoService2" protocol="rmi" /> <!--和本地bean一样实现服务 --> <bean id="demoService" class="com.test.dubboser.ServiceImp"/> <bean id="demoService2" class="com.test.dubboser.ServiceImp2"/> </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" /> <!-- 使用zookeeper广播注册中心暴露发现服务地址 --> <dubbo:registry protocol="zookeeper" address="192.168.0.101:2181" /> <dubbo:reference id="demoServicemy" interface="com.test.dubboser.ServiceDemo"/> <dubbo:reference id="demoServicemy2" interface="com.test.dubboser.ServiceDemo2"/> </beans>
消费端还是按照正常方式获取服务,只是传递使用的协议不同,底层tcp链接时常不同……
二、同一服务多协议配置
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.101:2181"/> <!-- 用dubbo协议在20880端口暴露服务 --> <dubbo:protocol name="dubbo" port="20880" /> <dubbo:protocol name="rmi" port="20881" /> <!-- 声明需要暴露的服务接口 --> <dubbo:service interface="com.test.dubboser.ServiceDemo" ref="demoService" protocol="dubbo,rmi" /> <!--和本地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" /> <!-- 使用zookeeper广播注册中心暴露发现服务地址 --> <dubbo:registry protocol="zookeeper" address="192.168.0.101:2181" /> <dubbo:reference id="demoServicemy3" interface="com.test.dubboser.ServiceDemo"/> </beans>
三、不同服务注册到不同的注册中心
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 id="bjregister" protocol="zookeeper" address="192.168.0.101:2181"/> <dubbo:registry id="shregister" protocol="zookeeper" address="192.168.0.101:2182"/> <!-- 用dubbo协议在20880端口暴露服务 --> <dubbo:protocol name="dubbo" port="20880" /> <!-- 声明需要暴露的服务接口 --> <!--不同服务注册到不同的注册中心 --> <dubbo:service interface="com.test.dubboser.ServiceDemo" ref="demoService" registry="bjregister" /> <dubbo:service interface="com.test.dubboser.ServiceDemo2" ref="demoService2" registry="shregister"/> <!--和本地bean一样实现服务 --> <bean id="demoService" class="com.test.dubboser.ServiceImp"/> <bean id="demoService2" class="com.test.dubboser.ServiceImp2"/> </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" /> <!-- 使用zookeeper广播注册中心暴露发现服务地址 --> <!--向两个注册中心订阅 --> <dubbo:registry protocol="zookeeper" address="192.168.0.101:2181"/> <dubbo:registry protocol="zookeeper" address="192.168.0.101:2182"/> <!--获取服务 --> <dubbo:reference id="demoServicemy" interface="com.test.dubboser.ServiceDemo"/> <dubbo:reference id="demoServicemy2" interface="com.test.dubboser.ServiceDemo2"/> </beans>根据服务接口通过不同的注册中心获取服务的具体信息然后获取这个服务的返回值,不同服务走不同的注册中心……
相关文章推荐
- Dubbo框架初探【用Spring配置声明暴露服务(可以使用multicast广播注册中心暴露服务地址或者使用zookeeper注册中心暴露服务地址)、加载Spring配置,启动服务】
- dubbo 学习(5) dubbo多协议和多注册中心
- Dubbo 学习(4)— zookeeper 注册中心的使用
- dubbo 学习(5) dubbo多协议和多注册中心
- Dubbo入门学习--协议及注册中心
- dubbo(分布式架构)+zookeeper(注册中心)+spring(provider和consumer) 基本使用
- Dubbo多协议和多注册中心
- Dubbo原理解析-注册中心之基于dubbo协议的简单注册中心实现
- dubbo 使用学习五(dubbo开发中使用到的一些服务配置方式)
- 阿里dubbo框架使用系列:开发环境搭建之zookeeper注册中心(单节点)
- zookeeper作为注册中心,使用dubbo
- Dubbo学习总结(3)——Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- NET(C#)接入Dubbo服务,Zookeeper作为Dubbo服务的注册中心,实现thrift协议访问接口(3)
- NET(C#)接入Dubbo服务,Zookeeper作为Dubbo服务的注册中心,实现thrift协议访问接口(2)
- Dubbo多协议和多注册中心
- 13. Dubbo原理解析-注册中心之Zookeeper协议注册中心
- NET(C#)接入Dubbo服务,Zookeeper作为Dubbo服务的注册中心,实现thrift协议访问接口(1)
- Dubbo学习总结(3)——Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- 12. Dubbo原理解析-注册中心之基于dubbo协议的简单注册中心实现
- NET(C#)接入Dubbo服务,Zookeeper作为Dubbo服务的注册中心,实现thrift协议访问接口(2)