Dubbo实战(三)多注册中心配置
来源:互联网 发布:淘宝无法收藏宝贝 编辑:程序博客网 时间:2024/05/01 21:39
本文将展示如何在Dubbo中进行多注册中心配置。
转载:http://blog.csdn.net/top_code/article/details/51935533
开发环境
- 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>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
待暴露的服务
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; }}
- 1
- 2
- 3
- 4
- 5
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
- 9
- 10
- 11
- 12
- 13
- 14
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>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
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>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
阅读全文
0 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)
- spring,mybatis事务管理配置与@Transactional注解使用
- C#简单窗体应用程序(三)
- 基于Unity3D的2d拾宝游戏(四)
- Java线程:volatile关键字
- PostgreSQL默认用户名与密码
- Dubbo实战(三)多注册中心配置
- Java线程
- 简单实现自定义View随手指拖动
- vs开发,添加try catch(...)发现没有捕获异常,需要对编译命令进行设置
- “师创杯”SDUT-ACM校赛正式赛-从零开始的异世界生活
- C++11使用make_shared的优势和劣势
- The Tag Game
- jsp(服务器目录结构)
- 6.6提纲