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单机配置:方式一. ...
随机推荐
- 树状数组 - BZOJ 1103 [POI2007]大都市
bzoj 1103 [POI2007]大都市 描述 在经济全球化浪潮的影响下,习惯于漫步在清晨的乡间小路的邮递员 Blue Mary也开始骑着摩托车传递邮件了.不过,她经常回忆起以前在乡间漫步的情景. ...
- pl/sql 函数及与存储过程的区别
函数用于返回特定的数据,当建立函数时,在函数头部必须包含return子句.而在函数体内必须包含return语句返回的数据.我们可以使用create function来建立函数. 1).接下来通过一个案 ...
- Welcome-to-Swift-06函数(Functions)
函数是执行特定任务的代码自包含块.给定一个函数名称标识, 当执行其任务时就可以用这个标识来进行"调用". Swift的统一的功能语法足够灵活来表达任何东西,无论是甚至没有参数名称的 ...
- 算法复习——状压dp
状压dp的核心在于,当我们不能通过表现单一的对象的状态来达到dp的最优子结构和无后效性原则时,我们可能保存多个元素的有关信息··这时候利用2进制的01来表示每个元素相关状态并将其压缩成2进制数就可以达 ...
- java面试题之如何中断一个线程?
方法一:调用interrupt方法,通知线程应该中断了: A.如果线程处于被阻塞状态,那么线程将立即退出被阻塞状态,并抛出了一个InterruptedException异常. B.如果线程处于正常活动 ...
- java中static变量和方法的总结
转自:http://blog.csdn.net/haobo920/article/details/5921621 java中static变量和方法的总结 java中一切皆是对象 一个类中对象的定义一般 ...
- Keepalived中Master和Backup角色选举策略
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://ixdba.blog.51cto.com/2895551/1544858 在Kee ...
- scrapy之Pipeline
官方文档:https://docs.scrapy.org/en/latest/topics/item-pipeline.html 激活pipeline,需要在settings里配置,然而这里配置的pi ...
- Thrift & RPC介绍
在学习thrift之前,先来看一下什么是rpc rpc远程过程调用,通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议.RPC采用客户机/服务器模式.请求程序就是一个客户机,而服务提供 ...
- 计算器(bzoj 2242)
Description 你被要求设计一个计算器完成以下三项任务: 1.给定y,z,p,计算Y^Z Mod P 的值: 2.给定y,z,p,计算满足xy≡ Z ( mod P )的最小非负整数: 3.给 ...