Dubbo的註冊中心有好多種,包括Multicast、Zookeeper、Redis和Simple等。Dubbo官方推薦使用Zookeeper註冊中心,我所使用過的也只是Zookeeper註冊中心。
首先介紹一下Zookeeper: ZooKeeper是一個分佈式的,開放源碼的分佈式應用程序協調服務,是Google的Chubby一個開源的實現,是Hadoop和Hbase的重要組件。它是一個爲分佈式應用提供一致性服務的軟件,提供的功能包括:配置維護、域名服務、分佈式同步、組服務等。
建議使用dubbo-2.3.3以上版本的zookeeper註冊中心客戶端
流程說明:
服務提供者啓動時 向/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:reference group="*" version="*" />,可訂閱服務的所有分組和所有版本的提供者。
ZKClient Zookeeper Registry
從2.2.0版本開始缺省爲zkclient實現,以提升zookeeper客戶端的健狀性。
缺省配置:
<dubbo:registry ... client="zkclient" />
或:
dubbo.registry.client=zkclient
或:
zookeeper://10.20.153.10:2181?client=zkclient
Curator Zookeeper Registry
從2.3.0版本開始支持可選curator實現。 如果需要改爲curator實現,請配置:
<dubbo:registry ... client="curator" />
或:
dubbo.registry.client=curator
或:
zookeeper://10.20.153.10:2181?client=curator
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" />