Dubbo实战(三)多注册中心配置
来源:互联网 发布:女士香水哪款好闻知乎 编辑:程序博客网 时间:2024/05/01 23:36
本文将展示如何在Dubbo中进行多注册中心配置。
开发环境
- JDK 1.7
- Maven 3.3.9
- Spring 4.2.7.RELEASE
Spring配置
<?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:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:task="http://www.springframework.org/schema/task" xmlns:util="http://www.springframework.org/schema/util" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" default-lazy-init="false"> <context:component-scan base-package="com.ricky.dubbo" /> <context:annotation-config /> <import resource="spring-dubbo.xml"/></beans>
待暴露的服务
package com.ricky.dubbo.provider.impl;import org.springframework.stereotype.Service;import com.ricky.dubbo.api.DemoService;import com.ricky.dubbo.api.model.User;@Service("demoService")public class DemoServiceImpl implements DemoService { @Override public String sayHello(String name) { return "Hello " + name; } @Override public User findUserById(long id) { User user = new User(); user.setId(id); user.setName("Ricky"); user.setAge(26); return user; }}
package com.ricky.dubbo.provider.impl;import org.springframework.stereotype.Service;import com.ricky.dubbo.api.HelloService;@Service("helloService")public class HelloServiceImpl implements HelloService { @Override public String sayHi(String msg) { return "Hello "+msg; }}
1、多注册中心注册
比如:有些服务只在A机房部署,而B机房的其它应用又需要引用此服务,那么可以将服务同时注册到两个注册中心。
spring-dubbo-multi-registry.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-app" /> <!-- 多注册中心配置 --> <dubbo:registry id="qd_registry" address="zookeeper://127.0.0.1:2181" /> <dubbo:registry id="wh_registry" address="zookeeper://127.0.0.1:2183" default="false" /> <!-- 用dubbo协议在20880端口暴露服务 --> <dubbo:protocol name="dubbo" port="20880" /> <!-- 声明需要暴露的服务接口 --> <dubbo:service interface="com.ricky.dubbo.api.HelloService" ref="helloService" registry="qd_registry,wh_registry" /></beans>
2、不同服务使用不同注册中心
比如:CRM有些服务是专门为国际站设计的,有些服务是专门为中文站设计的。
<?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-app" /> <!-- 多注册中心配置 --> <dubbo:registry id="qd_registry" address="zookeeper://127.0.0.1:2181" /> <dubbo:registry id="wh_registry" address="zookeeper://127.0.0.1:2183" default="false" /> <!-- 用dubbo协议在20880端口暴露服务 --> <dubbo:protocol name="dubbo" port="20880" /> <!-- 声明需要暴露的服务接口 --> <dubbo:service interface="com.ricky.dubbo.api.DemoService" ref="demoService" registry="qd_registry" /> <dubbo:service interface="com.ricky.dubbo.api.HelloService" ref="helloService" registry="wh_registry" /></beans>
参考资料
2 0
- Dubbo实战(三)多注册中心配置
- Dubbo实战(三)多注册中心配置
- Dubbo实战(三)多注册中心配置
- (三)dubbo注册中心-zookeeper
- Dubbo多注册中心
- Dubbo注册中心启动配置
- Dubbo学习笔记(三)------Zookeeper注册中心
- dubbo使用多注册中心
- Dubbo源代码实现三:注册中心Registry
- dubbo 使用学习六(多协议,多注册中心配置)
- Dubbo项目实战 (二) 注册中心zookeeper-3.4.6集群以及高可用
- SSM综合项目实战(TTSC) -- day02 Dubbo注册中心,通用Mapper,分页插件
- Dubbo多协议和多注册中心
- Dubbo多协议和多注册中心
- dubbo多协议和多注册中心
- dubbo多协议和多注册中心
- Dubbo学习(六):多注册中心
- Dubbo之旅--注册中心(2)
- Java单例模式——并非看起来那么简单
- 剑指offer----连续子数组的最大和----java实现
- hdu 1069
- spark编程python实例
- 删除Xcode描述文件
- Dubbo实战(三)多注册中心配置
- 拓扑排序与AOE图关键路径
- HDU1258 Sum It Up
- 创建动态链接库,使用自己的dll中的排序算法,用Qt将排序用时在界面上用表格的形式呈现出来
- BM字符串匹配算法
- 安卓内存优化之--内存泄露
- Lua5.2 请求 luasocket 相关模块时的 multiple-lua-vms-detected
- 重入锁ReentrantLock
- 独上高楼