dubbo和zookeeper结合使用
1、相关依赖引入
阿里的dubbo包含了spring相关内容,引入依赖时,需要排除,使用我们自己项目中的spring依赖
<!-- start..............dubbo.................-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
<exclusions>
<exclusion>
<artifactId>spring</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency> <dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency> <!-- end..............dubbo.................-->
xml配置文件中加入dubbo命名空间
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd"
2、Dubbo应用-Provider提供商
2.1、创建一个独立的service接口模块

2.2、创建service接口实现类模块
- 模块需要引用公共的dao模块
- 引用service接口模块
- 实现的service类加个名称

2.3、在resoures中添加spring的dao配置

2.4、在spring添加dubbo服务

<?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-4.3.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="edu-eb-service-provider" /> <!-- 使用zookeeper注册中心-->
<dubbo:registry protocol="zookeeper" address="192.168.1.110:2181"/> <!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880" /> <!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.yuxiu.edu.eb.service.IUserService" ref="userService" /> </beans>
ref="userService"原因:

也可以在配置文件中定义:

dubbo服务中model模型要序列化

2.5、发布微服务
public class App
{
public static void main( String[] args )
{
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring-context.xml");
context.start(); synchronized (App.class) {
while (true) {
try {
App.class.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
3、Dubbo应用-Comsumer消费者
3.1、添加一个Web模块,并引用服务接口模块

3.2、然后配置好springmvc
3.3、在spring的配置文件中配置dubbo的消费者
<?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-4.3.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
<dubbo:application name="edu-eb-web" /> <!-- 使用zookeeper注册中心暴露服务地址 -->
<!-- 注册中心地址 -->
<dubbo:registry protocol="zookeeper" address="192.168.1.110:2181" /> <!-- 用户服务接口 -->
<dubbo:reference interface="com.yuxiu.edu.eb.service.IUserService" id="userService" check="false" />
</beans>
3.4、配置个控制器调用service
其实也就是远程调用

4、Dubbo后台管理安装
- 将dubbo-admin-2.5.3.war放在tomcat7中执行
- 记得Java_Home要改成1.7,高版本的jdk不兼容
- 然后访问http://localhost:8888/dubbo-admin-2.5.3,帐号和密码默认都为root
- 要修改帐号和密码可以修改dubbo.properties文件



dubbo和zookeeper结合使用的更多相关文章
- dubbo连接zookeeper注册中心因为断网导致线程无限等待问题【转】
最近维护的系统切换了网络环境,由联通换成了电信网络,因为某些过滤规则导致系统连不上zookeeper服务器(应用系统机器在深圳,网络为电信线路,zookeeper服务器在北京,网络为联通线路),因为我 ...
- (转)Dubbo与Zookeeper、SpringMVC整合和使用
原文地址: https://my.oschina.net/zhengweishan/blog/693163 Dubbo与Zookeeper.SpringMVC整合和使用 osc码云托管地址:http: ...
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,Dubbo是一个分布式服务框架,在这种情况下诞生的.现在核心业务抽取出来,作为独立的服务,使 ...
- 160906、Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,Dubbo是一个分布式服务框架,在这种情况下诞生的.现在核心业务抽取出来,作为独立的服务,使 ...
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)转
互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,Dubbo是一个分布式服务框架,在这种情况下诞生的.现在核心业务抽取出来,作为独立的服务,使 ...
- 【转载】Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
http://blog.csdn.net/congcong68/article/details/41113239 互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及 ...
- Dubbo、Zookeeper、SpringMVC的整合使用
互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,Dubbo是一个分布式服务框架,在这种情况下诞生的.现在核心业务抽取出来,作为独立的服务,使 ...
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)(转)
互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,Dubbo是一个分布式服务框架,在这种情况下诞生的.现在核心业务抽取出来,作为独立的服务,使 ...
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)(转)
互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,Dubbo是一个分布式服务框架,在这种情况下诞生的.现在核心业务抽取出来,作为独立的服务,使 ...
- Dubbo与Zookeeper、SpringMVC整合和利用(负载均衡、容错)
互联网发展,扩大了网站应用程序的大小.传统的垂直应用架构已经无法应付.分布式服务架构和流量计算架构势在必行,Dubbo是一个分布式服务框架.在这样的情况下诞生的.如今核心业务抽取出来.作为独立的服务, ...
随机推荐
- Swift开源parser
https://www.prowidesoftware.com/products/core https://github.com/prowide/prowide-core-examples/blob/ ...
- Ubuntu14.04+安卓系统4.3+JDK6编译源码
本博客主要参照: https://www.jianshu.com/p/ecb9c132030f https://blog.csdn.net/gobitan/article/details/243674 ...
- WPF 绑定集合 根据集合个数改变样式 INotifyCollectionChanged
问题:当前ListBox Items 绑定 集合数据源ListA时候:ListA集合数据源中存在另外一个集合ListB,当更改或往ListB集合中添加数据的时候,通知改变? 实体类继承 INotify ...
- 一百二十:CMS系统之注册功能前后端逻辑
给提交按钮加一个id,方便写js js //发送ajax请求注册请求$(function () { $('#submit-btn').click(function (event) { event.pr ...
- const成员变量
#include <iostream> using namespace std; class A { public: A(int size) : SIZE(size) {}; privat ...
- Warning:detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd".
执行kubeadm init集群初始化时遇到: [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker ...
- day17 包与相对路径
""" 今日内容: 1.导入模块的细节 2.包的概念及使用 3.包的相对导入 """ """ 1.导入模块的细 ...
- 网络流三大算法【邻接矩阵+邻接表】POJ1273
网络流的基本概念跟算法原理我是在以下两篇博客里看懂的,写的非常好. http://www.cnblogs.com/ZJUT-jiangnan/p/3632525.html http://www.cnb ...
- [转帖]PKI技术原理(收集 整理 归纳)
PKI技术原理(收集 整理 归纳) https://blog.51cto.com/3layer/20430 总结归纳的 灰常好.. 7layer关注8人评论39427人阅读2007-03-14 11: ...
- ABC044 Digit Sum
题目链接 我的思路略复杂,这里介绍一个比较简洁的做法. 对于 $b \le \sqrt{N}$,暴力枚举 $b$.对于 $b > \sqrt{N}$, 注意到在 $b$ 进制下 $N$ 至多有 ...