All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.flood.cloud.zk.ZookeeperAutoConfiguration Maven / Gradle / Ivy

The newest version!
package cn.flood.cloud.zk;

import cn.flood.cloud.zk.properties.ZookeeperProperty;
import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

/**
 * redis 配置类
 *
 * @author zlt
 * @version 1.0
 * @date 2021/4/3
 * 

* Blog: https://zlt2000.gitee.io * Github: https://github.com/zlt2000 */ @EnableConfigurationProperties(ZookeeperProperty.class) @ComponentScan public class ZookeeperAutoConfiguration { /** * 初始化连接 */ @Bean(initMethod = "start", destroyMethod = "close") @ConditionalOnMissingBean public CuratorFramework curatorFramework(ZookeeperProperty property) { RetryPolicy retryPolicy = new ExponentialBackoffRetry(property.getBaseSleepTime(), property.getMaxRetries()); return CuratorFrameworkFactory.builder() .connectString(property.getConnectString()) .connectionTimeoutMs(property.getConnectionTimeout()) .sessionTimeoutMs(property.getSessionTimeout()) .retryPolicy(retryPolicy) .build(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy