curator - 创建客户端
引入依赖
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>5.2.0</version>
</dependency>
properties
@Data
@Component
@ConfigurationProperties(prefix = "curator.config")
public class CuratorConfigProperties {
private int retryCount;
private int elapsedTimeMs;
private String connectString;
private int sessionTimeout;
private int connectionTimeout;
}
创建客户端
@Configuration
public class CuratorConfiguration {
@Bean(initMethod = "start")
public CuratorFramework create(CuratorConfigProperties properties) {
return CuratorFrameworkFactory.builder()
.connectString(properties.getConnectString())
.sessionTimeoutMs(properties.getSessionTimeout())
.connectionTimeoutMs(properties.getConnectionTimeout())
.retryPolicy(new RetryNTimes(properties.getRetryCount(), properties.getElapsedTimeMs()))
.build();
}
}