dubbox 编译 和 测试

因为 dubbox 并没有发布到maven中央仓库仓库中,所以需要我们自己到官网下载,自己编译,install 到本地。

1. 首先安装git客户端工具 TortoiseGit, 然后使用它将 dubbox 从官网github地址:https://github.com/dangdangdotcom/dubbox clone到本地:

2. 使用mvn 编译:

在cmd 中执行:

E:Java_bookdubbodubboxdubbox>mvn install -Dmaven.test.skip=true

一般要几分钟到十几分钟,第一次有可能编译失败,失败时,重新执行命令就行,编译成功如下:

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] dubbo-parent ....................................... SUCCESS [  0.644 s]
[INFO] Hessian Lite(Alibaba embed version) ................ SUCCESS [  0.982 s]
[INFO] dubbo-common ....................................... SUCCESS [  0.744 s]
[INFO] dubbo-container .................................... SUCCESS [  0.013 s]
[INFO] dubbo-container-api ................................ SUCCESS [  0.127 s]
[INFO] dubbo-container-spring ............................. SUCCESS [  0.100 s]
[INFO] dubbo-container-javaconfig ......................... SUCCESS [  0.068 s]
[INFO] dubbo-container-jetty .............................. SUCCESS [  0.062 s]
[INFO] dubbo-container-log4j .............................. SUCCESS [  0.072 s]
[INFO] dubbo-container-logback ............................ SUCCESS [  0.081 s]
[INFO] dubbo-remoting ..................................... SUCCESS [  0.008 s]
[INFO] dubbo-remoting-api ................................. SUCCESS [  0.317 s]
[INFO] dubbo-remoting-netty ............................... SUCCESS [  0.105 s]
[INFO] dubbo-remoting-mina ................................ SUCCESS [  0.086 s]
[INFO] dubbo-remoting-grizzly ............................. SUCCESS [  0.092 s]
[INFO] dubbo-remoting-p2p ................................. SUCCESS [  0.120 s]
[INFO] dubbo-remoting-http ................................ SUCCESS [  0.097 s]
[INFO] dubbo-remoting-zookeeper ........................... SUCCESS [  0.121 s]
[INFO] dubbo-rpc .......................................... SUCCESS [  0.011 s]
[INFO] dubbo-rpc-api ...................................... SUCCESS [  0.233 s]
[INFO] dubbo-rpc-default .................................. SUCCESS [  0.157 s]
[INFO] dubbo-rpc-injvm .................................... SUCCESS [  0.064 s]
[INFO] dubbo-rpc-rmi ...................................... SUCCESS [  0.071 s]
[INFO] dubbo-rpc-hessian .................................. SUCCESS [  0.098 s]
[INFO] dubbo-rpc-http ..................................... SUCCESS [  0.079 s]
[INFO] dubbo-rpc-webservice ............................... SUCCESS [  0.145 s]
[INFO] dubbo-cluster ...................................... SUCCESS [  0.226 s]
[INFO] dubbo-registry ..................................... SUCCESS [  0.008 s]
[INFO] dubbo-registry-api ................................. SUCCESS [  0.109 s]
[INFO] dubbo-monitor ...................................... SUCCESS [  0.009 s]
[INFO] dubbo-monitor-api .................................. SUCCESS [  0.064 s]
[INFO] dubbo-filter ....................................... SUCCESS [  0.009 s]
[INFO] dubbo-filter-validation ............................ SUCCESS [  0.075 s]
[INFO] dubbo-filter-cache ................................. SUCCESS [  0.091 s]
[INFO] dubbo-registry-default ............................. SUCCESS [  0.076 s]
[INFO] dubbo-monitor-default .............................. SUCCESS [  0.073 s]
[INFO] dubbo-registry-multicast ........................... SUCCESS [  0.063 s]
[INFO] dubbo-config ....................................... SUCCESS [  0.012 s]
[INFO] dubbo-config-api ................................... SUCCESS [  0.139 s]
[INFO] dubbo-config-spring ................................ SUCCESS [  0.099 s]
[INFO] dubbo-rpc-thrift ................................... SUCCESS [  4.075 s]
[INFO] dubbo-rpc-memcached ................................ SUCCESS [  2.741 s]
[INFO] dubbo-rpc-redis .................................... SUCCESS [  2.312 s]
[INFO] dubbo-rpc-rest ..................................... SUCCESS [ 23.272 s]
[INFO] dubbo-registry-zookeeper ........................... SUCCESS [  1.666 s]
[INFO] dubbo-registry-redis ............................... SUCCESS [  1.792 s]
[INFO] dubbo .............................................. SUCCESS [ 26.157 s]
[INFO] dubbo-simple ....................................... SUCCESS [  0.010 s]
[INFO] dubbo-registry-simple .............................. SUCCESS [ 50.771 s]
[INFO] dubbo-monitor-simple ............................... SUCCESS [ 26.226 s]
[INFO] dubbo-admin ........................................ SUCCESS [ 56.042 s]
[INFO] dubbo-demo ......................................... SUCCESS [  0.012 s]
[INFO] dubbo-demo-api ..................................... SUCCESS [ 14.156 s]
[INFO] dubbo-demo-provider ................................ SUCCESS [  6.241 s]
[INFO] dubbo-demo-consumer ................................ SUCCESS [ 24.484 s]
[INFO] dubbo-test ......................................... SUCCESS [  0.012 s]
[INFO] dubbo-test-benchmark ............................... SUCCESS [  8.547 s]
[INFO] dubbo-test-compatibility ........................... SUCCESS [  0.062 s]
[INFO] dubbo-test-integration ............................. SUCCESS [  0.077 s]
[INFO] dubbo-test-examples ................................ SUCCESS [  5.373 s]
[INFO] dubbo-test-benchmark-api ........................... SUCCESS [  1.620 s]
[INFO] dubbo-test-benchmark-server ........................ SUCCESS [ 24.342 s]
[INFO] dubbo-test-benchmark-client ........................ SUCCESS [ 24.110 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 05:11 min
[INFO] Finished at: 2016-02-22T20:32:27+08:00
[INFO] Final Memory: 38M/157M
[INFO] ------------------------------------------------------------------------

在各个项目的 target 目录下,会生成 对应的 jar 文件:

3. 测试 dubbox:

先转换成 eclipse 项目,执行下面的命令:

E:Java_bookdubbodubboxdubbox>mvn eclipse:eclipse

然后导入 eclipse。

然后启动 zookeeper:

1) E:mycatzookeeper-3.4.6in>zkServer.cmd

2) 运行 dubbo-demo-providersrc estjavacomalibabadubbodemoproviderDemoProvider.java

成功时,zookeeper会显示如下的信息:

其中的 Error 不用管,没有关系。

到这里表示 dubbox 的服务成功注册到 zookeeper 中,下面测试服务消费者:

3) 运行:dubbo-demo-consumersrc estjavacomalibabadubbodemoconsumerDemoConsumer.java

可以在eclipse控制台看到类似下面的信息:

[22/02/16 09:18:20:020 CST] main  INFO support.LoggingFilter:  [DUBBO] The HTTP headers are: 
Accept: application/json;charset=UTF-8
Accept-Encoding: gzip, deflate
Content-Type: application/json
, dubbo version: 2.0.0, current host: 192.168.1.3
Writer interceptor invoked
Dynamic writer interceptor invoked
[22/02/16 09:18:21:021 CST] main  INFO support.LoggingFilter:  [DUBBO] The contents of response body is: 
{"id":1,"username":"larrypage"}
, dubbo version: 2.0.0, current host: 192.168.1.3
[22/02/16 09:18:22:022 CST] main  INFO support.LoggingFilter:  [DUBBO] The HTTP headers are: 
Content-Type: application/json;charset=UTF-8
Date: Mon, 22 Feb 2016 13:18:22 GMT
Server: Apache-Coyote/1.1
Transfer-Encoding: chunked
, dubbo version: 2.0.0, current host: 192.168.1.3
Client response filter invoked
Reader interceptor invoked
Dynamic reader interceptor invoked
[22/02/16 09:18:22:022 CST] main  INFO support.LoggingFilter:  [DUBBO] The contents of request body is: 
{"id":9}
, dubbo version: 2.0.0, current host: 192.168.1.3
SUCCESS: registered user with id 9
Client request filter invoked
[22/02/16 09:18:22:022 CST] main  INFO support.LoggingFilter:  [DUBBO] The HTTP headers are: 
Accept: application/json;charset=UTF-8
Accept-Encoding: gzip, deflate
, dubbo version: 2.0.0, current host: 192.168.1.3
[22/02/16 09:18:22:022 CST] main  INFO support.LoggingFilter:  [DUBBO] The HTTP headers are: 
Content-Type: application/json;charset=UTF-8
Date: Mon, 22 Feb 2016 13:18:22 GMT
Server: Apache-Coyote/1.1
Transfer-Encoding: chunked
, dubbo version: 2.0.0, current host: 192.168.1.3
Client response filter invoked
Reader interceptor invoked
Dynamic reader interceptor invoked
[22/02/16 09:18:22:022 CST] main  INFO support.LoggingFilter:  [DUBBO] The contents of request body is: 
{"id":1,"username":"username1"}
, dubbo version: 2.0.0, current host: 192.168.1.3
SUCCESS: got user User (id=1, name='username1')
[22/02/16 09:18:22:022 CST] main  INFO container.Main:  [DUBBO] Dubbo SpringContainer started!, dubbo version: 2.0.0, current host: 192.168.1.3
[2016-02-22 21:18:22] Dubbo service server started!

SUCCESS: got user User (id=1, name='username1')

调用成功。

运行:dubbo-demo-consumersrc estjavacomalibabadubbodemoconsumerRestClient.java

浏览访问:http://localhost:8888/services/users/100.json

显示如下:

rest 调用成功。

这里 编译和测试的 master 分支,实际应用时我们一般下载官方的release版本,比如:

https://github.com/dangdangdotcom/dubbox/releases/tag/dubbox-2.8.4

进行编译。

参考:http://www.cnblogs.com/yjmyzz/p/dubbox-demo.html

原文地址:https://www.cnblogs.com/digdeep/p/5208195.html