Dubbo zookeeper 初探
先把zookeeper在本地给安装好,
安装方法参考:http://blog.csdn.net/wxwzy738/article/details/16330253
这里的话讲述了两个工程一个工程是提供服务的,一个工程是调用服务的,因为dubbo是跟spring进行无缝连接的,故功能配置在spring的配置文件中,跟spring进行整合开发
1、工程是以maven进行构建的,使用的jar包如下:
2、服务提供者的工程
a、dubbo-demo-api 定义接口
- public interface IProcessData {
- public String deal(String data);
- }
b、dubbo-demo-provider 服务提供者
- public class ProcessDataImpl implements IProcessData {
- /*
- * @see com.xxx.bubbo.provider.IProcessData#deal(java.lang.String)
- */
- @Override
- public String deal(String data) {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- return "Finished:" + data;
- }
- }
c、applicationProvider.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
- ">
- <!-- Application name -->
- <dubbo:application name="hello-world-app" />
- <!-- registry address, used for service to register itself -->
- <dubbo:registry address="zookeeper://127.0.0.1:2181" />
- <!-- expose this service through dubbo protocol, through port 20880 -->
- <!--
- <dubbo:protocol name="dubbo" port="20880" />
- <dubbo:protocol name="dubbo" port="9090" server="netty"
- client="netty" codec="dubbo" serialization="hessian2" charset="UTF-8"
- threadpool="fixed" threads="100" queues="0" iothreads="9" buffer="8192"
- accepts="1000" payload="8388608" />
- -->
- <!-- Service interface Concurrent Control -->
- <dubbo:service interface="com.huangjie.dubbo_Service.service.IProcessData"
- ref="demoService" executes="10" />
- <!-- Default Protocol -->
- <!--
- <dubbo:protocol server="netty" />
- -->
- <!-- designate implementation -->
- <bean id="demoService" class="com.huangjie.dubbo_Service.service.impl.ProcessDataImpl" />
- </beans>
d、启动服务
- public class DubboProviderMain {
- public static void main(String[] args) throws Exception {
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
- new String[]{"applicationProvider.xml"});
- context.start();
- System.out.println("Press any key to exit.");
- System.in.read();
- }
- }
3、服务调用者的工程
a、调用类
- public class ConsumerThd implements Runnable {
- /*
- * @see java.lang.Runnable#run()
- */
- @Override
- public void run() {
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
- new String[]{"applicationConsumer.xml"});
- context.start();
- IProcessData demoService = (IProcessData) context.getBean("demoService"); // get
- // service
- // invocation
- // proxy
- String hello = demoService.deal("nihao"); // do invoke!
- System.out.println(Thread.currentThread().getName() + " "+hello);
- }
- public static void main(String[] args) {
- new Thread(new ConsumerThd()).start();
- /**
- * 输出结果:
- * Thread-0 Finished:nihao
- */
- }
- }
b、applicationConsumer.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
- ">
- <!-- consumer application name -->
- <dubbo:application name="consumer-of-helloworld-app" />
- <!-- registry address, used for consumer to discover services -->
- <dubbo:registry address="zookeeper://127.0.0.1:2181" />
- <dubbo:consumer timeout="5000"/>
- <!-- which service to consume? -->
- <dubbo:reference id="demoService" interface="com.huangjie.dubbo_Service.service.IProcessData" />
- </beans>
4、最后需要把zookeeper的服务给启动,在zookeeper安装文件夹下面的bin目录里面的zkServer.cmd给点击运行。不要关闭窗口,保持服务运行
这样整个调用就完成了,这样的好处是只要远程提供ip地址及端口号,以及对外调用的类,客户端就可以调用,客户端不必知道服务端的地址之类的
而且服务端可以开多个zookeeper服务,这样如果其中一个zookeeper 服务死掉了,其他服务还能正常运行
Dubbo zookeeper 初探的更多相关文章
- 从头开始搭建一个dubbo+zookeeper平台
本篇主要是来分享从头开始搭建一个dubbo+zookeeper平台的过程,其中会简要介绍下dubbo服务的作用. 首先,看下一般网站架构随着业务的发展,逻辑越来越复杂,数据量越来越大,交互越来越多之后 ...
- 通过单元测试理解spring容器以及dubbo+zookeeper单元测试异常处理
一.先说一个结论:单元测试与主项目的spring容器是隔离的,也就是说,单元测试无法访问主项目spring容器,需要自己加载spring容器. 接下来是代码实例,WEB主项目出于运行状态,单元测试中可 ...
- 用dubbo+zookeeper+spring搭建一个简单的http接口程序
dubbo是一个分布式服务框架,是阿里巴巴开发的一个解决RPC远程调用优化的核心框架,包含负载均衡算法,能提高分布式系统的性能. zookeeper是hadoop的一个子项目,主要用来解决分布式系统的 ...
- Springboot 整合 Dubbo/ZooKeeper 详解 SOA 案例
摘要: 原创出处:www.bysocket.com 泥瓦匠BYSocket 希望转载,保留摘要,谢谢! “看看星空,会觉得自己很渺小,可能我们在宇宙中从来就是一个偶然.所以,无论什么事情,仔细想一 ...
- 精华【分布式、微服务、云架构、dubbo+zookeeper+springmvc+mybatis+shiro+redis】分布式大型互联网企业架构!
平台简介 Jeesz是一个分布式的框架,提供项目模块化.服务化.热插拔的思想,高度封装安全性的Java EE快速开发平台. Jeesz本身集成Dubbo服务管控.Zookeeper注册中心.Redis ...
- 分布式服务:Dubbo+Zookeeper+Proxy+Restful 分布式架构
分布式 分布式服务:Dubbo+Zookeeper+Proxy+Restful 分布式消息中间件:KafKa+Flume+Zookeeper 分布式缓存:Redis 分布式文件:FastDFS ...
- 分布式架构真正适用于大型互联网项目的架构! dubbo+zookeeper+springmvc+mybatis+shiro+redis
分类: 分布式技术(3) 目录(?)[+] 平台简介 Jeesz是一个分布式的框架,提供项目模块化.服务化.热插拔的思想,高度封装安全性的Java EE快速开发平台. Jeesz本身集成D ...
- dubbo+zookeeper+jenkins从打包开始
一.jenkins中maven构建 有如下图构建设置 解释说明: pom.xml 此处jenkins打包依赖的主要配置文件(规则) settings.xml 全局配置文件,主要用于配置maven的运行 ...
- Dubbo+zookeeper构建高可用分布式集群(二)-集群部署
在Dubbo+zookeeper构建高可用分布式集群(一)-单机部署中我们讲了如何单机部署.但没有将如何配置微服务.下面分别介绍单机与集群微服务如何配置注册中心. Zookeeper单机配置:方式一. ...
随机推荐
- loj2254 「SNOI2017」一个简单的询问
ref #include <algorithm> #include <iostream> #include <cstdio> #include <cmath& ...
- 实现类似QQ单一账户登录,在另一个地方登录后在原登录窗口提示下线
首先,使用框架做的最好,可以在框架页直接做一次就好了 再登陆成功后保存session的代码后添加以下代码: 注意:需要引入命名空间using System.Collections; SetApplic ...
- Spring core resourc层结构体系及JDK与Spring对classpath中资源的获取方式及结果对比
1. Spring core resourc层结构体系 1.1. Resource相关结构体系 1.2. ResourceLoader相关体系 2. JDK与Spring对classpath中资源的获 ...
- Selenium WebDriver-判断页面中某一元素是否可操作
driver.get("http://127.0.0.1/test_enable.html") i1=driver.find_element_by_id("input1& ...
- Leetcode 474.一和零
一和零 在计算机界中,我们总是追求用有限的资源获取最大的收益. 现在,假设你分别支配着 m 个 0 和 n 个 1.另外,还有一个仅包含 0 和 1 字符串的数组. 你的任务是使用给定的 m 个 0 ...
- Model View Controller(MVC) in PHP
The model view controller pattern is the most used pattern for today’s world web applications. It ha ...
- spring AOP详解二
AOP实例(通过Proxy代理模式) Spring AOP使用纯java实现,不需要专门的编译过程和类装载器,它在运行期间通过代理方式向目标类织入增强代码,它更侧重于提供一种和Spring IoC容器 ...
- 剑指offer 面试题38
面试题38:数字在排序数组中出现的次数 题目:统计一个数字在排序数组中出现的次数.例如输入排序数组{1,2,3,3,3,3,4,5}和数字3,由于3在这个数组中出现了4次,因此输出4. 主要的思路是进 ...
- (转)Java字符串整形(例:0001)
原文地址:https://blog.csdn.net/xuexiiphone/article/details/51372692 caseID = preFix + String.format(&quo ...
- Eclipse + Apache Axis2 发布RESTful WebService(三)第一个程序Hello Axis2 !(未成功)
此路不通 Axis2发布SOAP WebService非常简单,建一个Dynamic Web Project,然后为它建一个Axis的Web Service(Tomcat7+JDK),就会生成Clas ...