http://code.alibabatech.com/wiki/display/dubbo/User+Guide#UserGuide-RequiredDependencies
Zookeeper Registry
?
建議使用dubbo-2.3.3以上版本的zookeeper注冊中心客戶端
?
Zookeeper說明
Zookeeper是Apacahe Hadoop的子項目,是一個樹型的目錄服務,支持變更推送,適合作為Dubbo服務的注冊中心,工業強度較高,可用于生產環境,并推薦使用,參見:
http://zookeeper.apache.org
?
Zookeeper安裝
安裝方式參見:?
Zookeeper安裝手冊
,只需搭一個原生的Zookeeper服務器,并將
Quick Start
中Provider和Consumer里的conf/dubbo.properties中的dubbo.registry.addrss的值改為zookeeper://127.0.0.1:2181即可使用
?
?
?
流程說明:
-
服務提供者啟動時
- 向/dubbo/com.foo.BarService/providers目錄下寫入自己的URL地址。
-
服務消費者啟動時
- 訂閱/dubbo/com.foo.BarService/providers目錄下的提供者URL地址。
- 并向/dubbo/com.foo.BarService/consumers目錄下寫入自己的URL地址。
-
監控中心啟動時
- 訂閱/dubbo/com.foo.BarService目錄下的所有提供者和消費者URL地址。
支持以下功能:
- 當提供者出現斷電等異常停機時,注冊中心能自動刪除提供者信息。
- 當注冊中心重啟時,能自動恢復注冊數據,以及訂閱請求。
- 當會話過期時,能自動恢復注冊數據,以及訂閱請求。
- 當設置<dubbo:registry check="false" />時,記錄失敗注冊和訂閱請求,后臺定時重試。
- 可通過<dubbo:registry username="admin" password="1234" />設置zookeeper登錄信息。
- 可通過<dubbo:registry group="dubbo" />設置zookeeper的根節點,缺省為dubbo。
- 支持*號通配符<dubbo:reference group="*" version="*" />,可訂閱服務的所有分組和所有版本的提供者。
在provider和consumer中增加zookeeper客戶端jar包依賴:
<
dependency
>
????
<
groupId
>org.apache.zookeeper</
groupId
>
????
<
artifactId
>zookeeper</
artifactId
>
????
<
version
>3.3.3</
version
>
</
dependency
>
|
或直接下載: http://repo1.maven.org/maven2/org/apache/zookeeper/zookeeper
支持zkclient和curator兩種Zookeeper客戶端實現:
?
ZKClient Zookeeper Registry
從2.2.0版本開始缺省為zkclient實現,以提升zookeeper客戶端的健狀性。
ZKClient是Datameer開源的一個Zookeeper客戶端實現,開源比較早,參見: https://github.com/sgroschupf/zkclient |
缺省配置:
<
dubbo:registry
?
...
client
=
"zkclient"
?
/>
|
或:
dubbo.registry.client=zkclient
|
或:
zookeeper://10.20.153.10:2181?client=zkclient
|
需依賴:
<
dependency
>
????
<
groupId
>com.github.sgroschupf</
groupId
>
????
<
artifactId
>zkclient</
artifactId
>
????
<
version
>0.1</
version
>
</
dependency
>
|
或直接下載: http://repo1.maven.org/maven2/com/github/sgroschupf/zkclient
?
Curator Zookeeper Registry
從2.3.0版本開始支持可選curator實現。
Curator是Netflix開源的一個Zookeeper客戶端實現,比較活躍,參見: https://github.com/Netflix/curator |
如果需要改為curator實現,請配置:
<
dubbo:registry
?
...
client
=
"curator"
?
/>
|
或:
dubbo.registry.client=curator
|
或:
zookeeper://10.20.153.10:2181?client=curator
|
需依賴:
<
dependency
>
????
<
groupId
>com.netflix.curator</
groupId
>
????
<
artifactId
>curator-framework</
artifactId
>
????
<
version
>1.1.10</
version
>
</
dependency
>
|
或直接下載: http://repo1.maven.org/maven2/com/netflix/curator/curator-framework
Zookeeper單機配置:
<
dubbo:registry
?
address
=
"zookeeper://10.20.153.10:2181"
?
/>
|
Or:
<
dubbo:registry
?
protocol
=
"zookeeper"
?
address
=
"10.20.153.10:2181"
?
/>
|
Zookeeper集群配置:
<
dubbo:registry
address
=
"zookeeper://10.20.153.10:2181?backup=10.20.153.11:2181,10.20.153.12:2181"
?
/>
|
Or:
<
dubbo:registry
?
protocol
=
"zookeeper"
address
=
"10.20.153.10:2181,10.20.153.11:2181,10.20.153.12:2181"
?
/>
|
同一Zookeeper,分成多組注冊中心:
<
dubbo:registry
?
id
=
"chinaRegistry"
?
protocol
=
"zookeeper"
?
address
=
"10.20.153.10:2181"
group
=
"china"
?
/>
<
dubbo:registry
?
id
=
"intlRegistry"
?
protocol
=
"zookeeper"
?
address
=
"10.20.153.10:2181"
group
=
"intl"
?
/>
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
