浅谈dubbo和Zookeeper分布式技术的使用

一、基本概念:
1)Dubbo是管理中间层的工具,在业务层到数据仓库间有非常多服务的接入和服务提供者需要调度,
dubbo提供一个框架解决这个问题。这个框架要完成调度必须要有一个分布式的注册中心,
存储所有服务的元数据,用到zookeeper。
2)zookeeper用来注册服务和负载均衡。

二、dubbo和zookeeper的使用:
1、引入相关依赖
下面的放在父工程下:

4.12 5.0.5.RELEASE4.1.4 2.5 2.6.0 3.4.7 0.1 3.4.5 1.3.1 1.2.15 5.1.32 1.0.9 1.3.1 5.0.5.RELEASE com.alibaba dubbo ${dubbo.version} org.apache.zookeeper zookeeper ${zookeeper.version} com.github.sgroschupf zkclient ${zkclient.version} junit junit 4.12 com.alibaba fastjson 1.2.47 javassist javassist 3.12.1.GA commons-codec commons-codec 1.10 com.github.pagehelper pagehelper ${pagehelper.version}

下面的放在公共模块下:
com.alibaba dubbo org.apache.zookeeper zookeeper com.github.sgroschupf zkclient junit junit com.alibaba fastjson javassist javassist commons-codec commons-codec


2、在公共模块的resources添加zk.properties配置文件。
zk.address=localhost:2181


3、在服务公共模块的resources添加服务公共模块applicationContext-dubbo.xml配置文件。

【浅谈dubbo和Zookeeper分布式技术的使用】
4、在web公共模块的resources添加web公共模块的applicationContext-dubbo.xml配置文件。


5、在服务子模块的resources添加服务子模块dubbo.properties配置文件。
dubbo.port=20881 dubbo.application=goods


6、在web子模块的resources添加web子模块的dubbo.properties配置文件。
dubbo.application=manager


7、解压zookeeper安包,在conf下添加zoo.cfg配置文件,要使用时,在bin下双击启动zkServer.cmd
zoo.cfg配置文件:
# The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/tmp/zookeeper # the port at which the clients will connect clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1

zookeeper安装包如果有需要可以私聊!!!

    推荐阅读