Apache Curator
Curator(館長) VS. ZooKeeper(動物園管理員) ???🐒 🐵 🙈
🙉起名字真好玩。🙊 我猜是要管理動物園管理員?
1. 優點
- 封裝ZooKeeper client與ZooKeeper server之間的連接處理。
- 提供了一套Fluent風格的操作API。
- 提供ZooKeeper各種應用場景(recipe, 比如共享鎖服務, 集羣領導選舉機制)的抽象封裝。
2. 組成部分
- Client:Zookeeper客戶端(ZooKeeper類)的替代品,提供一些非常有用的客戶端特性。
- Framework:用來簡化Zookeeper高級功能的使用(Zookeeper API的高層封裝),並增加了一些新功能,比如連接管理(管理到Zookeeper集羣的連接),重試處理。
- Recipes:Zookeeper典型應用場景的實現,基於Curator Framework。
- Utilities:各種ZK的工具。
- Errors:Curator異常處理,連接,恢復等。
- Extensions:recipes的擴展。
3. 版本問題
目前Curator有2.x.x和3.x.x兩個系列的版本,支持不同版本的Zookeeper。其中Curator 2.x.x兼容Zookeeper的3.4.x和3.5.x。而Curator 3.x.x只兼容Zookeeper 3.5.x,並且提供了一些諸如動態重新配置、watch刪除等新特性。
具體在curator官網有介紹。
<!-- 只需要導入這個依賴 就會自動導入其他依賴 -->
<!-- All of the recipes listed on the ZooKeeper recipes doc (except two phase commit). -->
<!-- 封裝了一些高級特性,如:Cache事件監聽、選舉、分佈式鎖、分佈式計數器、分佈式Barrier等 -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>4.2.0</version>
</dependency>
<!-- High-level API that greatly simplifies using ZooKeeper. -->
<!-- 對ZooKeeper底層Api的封裝 -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>4.2.0</version>
</dependency>
<!-- Unit testing utilities. -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
<version>4.2.0</version>
<scope>test</scope>
</dependency>
<!-- Low-level API -->
<!-- 提供了一些客戶端操作,如重試策略 -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-client</artifactId>
<version>4.2.0</version>
</dependency>
<!-- A service discovery recipe. -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-x-discovery</artifactId>
<version>4.2.0</version>
</dependency>
<!-- 異步調用包 -->
<!-- Java 8 Async DSL -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-x-async</artifactId>
<version>4.2.0</version>
</dependency>