dubbo +zookeeper +spring Boot框架整合与dubbo泛型调用演示
By:客 授客 QQ:1033553122 欢迎加入全国软件测试交流 QQ 群:7156436
测试环境 1
实践过程 2
Java运行配置 2
zookeeper运行与配置 2
配置 2
运行 3
测试 3
Maven运行与配置 5
配置 5
Repository设置(可选) 6
利用maven打dubbo-admin-0.0.1-SNAPSHOT.jar包 8
dubbo-admin控制台运行与配置 9
配置(可选) 9
运行 9
编码 11
Maven mirrors配置 11
Idea maven运行环境配置 12
新建项目 14
新建父项目 14
新建模块 19
dubbo-demo-api模块编码 23
dubbo-demo-provider模块编码与配置 23
dubbo-dubbo-consumer模块编码 28
参考链接 32
Dubbo特性-泛型调用 32
依赖spring配置文件的泛型调用 32
不依赖Spring配置文件的泛型调用 33
泛型调用-传递更复杂的参数类型 34
参考链接 39
测试环境
服务端
CentOS 7操作系统(CentOS-7-x86_64-DVD-1503-01.iso)
下载地址:http://ftp.riken.jp/Linux/centos/7/isos/x86_64/
zookeeper-3.4.13.tar.gz
下载地址:
http://zookeeper.apache.org/releases.html
http://mirror.bit.edu.cn/apache/zookeeper/
https://pan.baidu.com/s/1Ug4hQ6PVQJmIhghyX4UIkQ
Java(jdk-8u65-linux-x64.tar.gz)
下载地址:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
incubator-dubbo-ops-master.zip
下载地址:
https://github.com/apache/incubator-dubbo-ops
https://pan.baidu.com/s/10Qu9IQa9RCmUyeSQLFpSkQ
客户端
Win7
apache-maven-3.5.4-bin.zip
https://maven.apache.org/download.cgi
https://pan.baidu.com/s/1OUNC0kZNduXJJLbpw76GZA
ideaIU-2018.2.1.exe
实践过程
Java运行配置
略
zookeeper运行与配置
配置
注:以下为单例模式运行下的配置
# tar xvzf zookeeper-3.4.13.tar.gz
# mkdir -p /var/lib/zookeeper
# cd zookeeper-3.4.13/
// 手工创建zoo.cfg配置
# cd conf/
# vim zoo.cfg //内容如下
tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181
说明:
dataDir
tickTime 供Zookeeper使用的基本时间单位(单位毫秒),用于执行心跳,同时最小会话超时时间将会是tickTime的两倍。
dataDir 必须指向一个已存在目录,用于存在内存数据库快照,除非特别指明,否则为更新至数据库的事务日志(the location to store the in-memory database snapshots and, unless specified otherwise, the transaction log of updates to the database.)
clientPort 用于监听客户端连接的端口。
运行
# cd ../bin
# pwd
/usr/local/zookeeper/zookeeper-3.4.13/bin
# ls
README.txt zkCleanup.sh zkCli.cmd zkCli.sh zkEnv.cmd zkEnv.sh zkServer.cmd zkServer.sh zkTxnLogToolkit.cmd zkTxnLogToolkit.sh
# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-3.4.13/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
注:停止运行 zkServer.sh stop
测试
连接到ZooKeeper
# zkCli.sh -server 127.0.0.1:2181
Connecting to 127.0.0.1:2181
2017-09-15 20:48:06,986 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.13-2d71af4dbe22557fda74f9a9b4309b15a7487f03, built on 06/29/2018 04:05 GMT
……(略)
Welcome to ZooKeeper!
2017-09-15 20:48:07,153 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1029] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
……(略)
ZooKeeper -server host:port cmd args
stat path [watch]
set path data [version]
ls path [watch]
delquota [-n|-b] path
ls2 path [watch]
setAcl path acl
setquota -n|-b val path
history
redo cmdno
printwatches on|off
delete path [version]
sync path
listquota path
rmr path
get path [watch]
create [-s] [-e] path data acl
addauth scheme auth
quit
getAcl path
close
connect host:port
[zk: 127.0.0.1:2181(CONNECTED) 1] ls /
[zookeeper]
[zk: 127.0.0.1:2181(CONNECTED) 2] create /zk_test my_data
Created /zk_test
[zk: 127.0.0.1:2181(CONNECTED) 3] ls /
[zookeeper, zk_test]
[zk: 127.0.0.1:2181(CONNECTED) 4] get /zk_test
my_data
cZxid = 0x2
ctime = Fri Sep 15 20:52:32 CST 2017
mZxid = 0x2
mtime = Fri Sep 15 20:52:32 CST 2017
pZxid = 0x2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 7
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 5] set /zk_test junk
cZxid = 0x2
ctime = Fri Sep 15 20:52:32 CST 2017
mZxid = 0x3
mtime = Fri Sep 15 20:54:39 CST 2017
pZxid = 0x2
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 6] get /zk_test
junk
cZxid = 0x2
ctime = Fri Sep 15 20:52:32 CST 2017
mZxid = 0x3
mtime = Fri Sep 15 20:54:39 CST 2017
pZxid = 0x2
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 7] delete /zk_test
参考链接:
http://zookeeper.apache.org/doc/current/zookeeperStarted.html
http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_systemReq
http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_configuration
Maven运行与配置
确保安装了java jdk并正确设置了JAVA_HOME
配置
下载bin.zip压缩包,解压到目标路径(例中 D:\Program Files\apache-maven-3.5.4\
),设置MAVEN_HOME环境变量,如下
Cmd输入mvn -v测试