com.nepxion.discovery.common.consul.configuration.ConsulAutoConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of discovery-common-consul Show documentation
Show all versions of discovery-common-consul Show documentation
Nepxion Discovery is a solution for Spring Cloud with blue green, gray, weight, limitation, circuit breaker, degrade, isolation, monitor, tracing, dye, failover, async agent
package com.nepxion.discovery.common.consul.configuration;
/**
* Title: Nepxion Discovery
* Description: Nepxion Discovery
* Copyright: Copyright (c) 2017-2050
* Company: Nepxion
* @author Congwei Xu
* @version 1.0
*/
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import com.ecwid.consul.v1.ConsulClient;
import com.nepxion.discovery.common.consul.constant.ConsulConstant;
import com.nepxion.discovery.common.consul.operation.ConsulOperation;
import com.nepxion.discovery.common.exception.DiscoveryException;
@Configuration
public class ConsulAutoConfiguration {
@Autowired
private Environment environment;
@Bean
public ConsulOperation consulOperation() {
return new ConsulOperation();
}
@Bean
@ConditionalOnMissingBean
public ConsulClient consulClient() {
String consulHost = environment.getProperty(ConsulConstant.CONSUL_HOST);
if (StringUtils.isBlank(consulHost)) {
throw new DiscoveryException(ConsulConstant.CONSUL_HOST + " can't be null or empty");
}
int consulPort = environment.getProperty(ConsulConstant.CONSUL_PORT, Integer.class);
return new ConsulClient(consulHost, consulPort);
}
}