程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> JAVA綜合教程 >> dubbox 編譯 和 測試,dubbox編譯測試

dubbox 編譯 和 測試,dubbox編譯測試

編輯:JAVA綜合教程

dubbox 編譯 和 測試,dubbox編譯測試


因為 dubbox 並沒有發布到maven中央倉庫倉庫中,所以需要我們自己到官網下載,自己編譯,install 到本地。

1. 首先安裝git客戶端工具 TortoiseGit, 然後使用它將 dubbox 從官網github地址:https://github.com/dangdangdotcom/dubbox clone到本地:

2. 使用mvn 編譯:

在cmd 中執行:

E:\Java_book\dubbo\dubbox\dubbox>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_book\dubbo\dubbox\dubbox>mvn eclipse:eclipse

然後導入 eclipse。

然後啟動 zookeeper:

1) E:\mycat\zookeeper-3.4.6\bin>zkServer.cmd

2) 運行 dubbo-demo-provider\src\test\java\com\alibaba\dubbo\demo\provider\DemoProvider.java

成功時,zookeeper會顯示如下的信息:

其中的 Error 不用管,沒有關系。

到這裡表示 dubbox 的服務成功注冊到 zookeeper 中,下面測試服務消費者:

3) 運行:dubbo-demo-consumer\src\test\java\com\alibaba\dubbo\demo\consumer\DemoConsumer.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-consumer\src\test\java\com\alibaba\dubbo\demo\consumer\RestClient.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

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved