在學習Dubbo分布式框架時的官方入門例子,很有代表性。簡單清晰。
有關Dubbo的概念、概述和簡單的配置文件,可以看官方文檔的簡述
會很快對Duboo有個整體的概念。
準備工作:
- 下載示例,點擊這里下載,建議用git管理。
- 下載注冊中心,推薦ZooKeeper,點擊這里下載
首先完成Zookeeper的安裝配置
- 解壓后,在conf目錄下增加一個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.
dataDir=D:\\zookeeper-3.4.12\\data
dataDirLog=D:\\zookeeper-3.4.12\\log
# the port at which the clients will connect
clientPort=2181
- 根據你上述配置的目錄(dataDir、dataDirLog),在根目錄中新建它們。
- 點擊bin目錄下的zkServer.cmd啟動
項目配置運行
- 打開項目
- 項目是Maven管理的多模塊項目,首先引入多模塊。
- 找到我們演示的Demo項目
- 將consumer和provider模塊的xml下的注冊中心配置全都換成ZooKeeper
參數用途簡介: - 先運行Provider.java,再運行Consumer.java(確保打開了Zookeeper注冊中心)
- 運行效果圖
Consumer不斷調用Provider提供的實現類,所呈現出的效果。