maven配置:

  

<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>2.6.0</version>
<type>jar</type>
<exclusions>
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>2.6.0</version>
<type>jar</type>
</dependency>

代码:

  创建客户端:

    

CuratorFramework curator= CuratorFrameworkFactory.builder()
.connectString("")
.sessionTimeoutMs(10000)
.retryPolicy(retryPolicy)
.build();

参数解释:

  好用的zookeeper客服端----Curator初探-LMLPHP

RetryPolicy详解:

继承关系:

  好用的zookeeper客服端----Curator初探-LMLPHP

好用的zookeeper客服端----Curator初探-LMLPHP

ExponentialBackoffRetry:

好用的zookeeper客服端----Curator初探-LMLPHP

RetryNTimes & RetryOneTime:

好用的zookeeper客服端----Curator初探-LMLPHP

RetryUntilElapsed:

好用的zookeeper客服端----Curator初探-LMLPHP

05-11 20:48