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

org.zodiac.autoconfigure.bootstrap.config.client.AppConfigClientBootstrapConfiguration Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.autoconfigure.bootstrap.config.client;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.retry.interceptor.RetryInterceptorBuilder;
import org.springframework.retry.interceptor.RetryOperationsInterceptor;
import org.zodiac.autoconfigure.bootstrap.condition.ConditionalOnAppConfigClientEnabled;
import org.zodiac.commons.constants.Constants;
import org.zodiac.commons.constants.SystemPropertiesConstants;
import org.zodiac.core.bootstrap.config.AppPropertySourceLocator;
import org.zodiac.core.bootstrap.config.client.CompositeAppPropertySourceLocator;
import org.zodiac.core.bootstrap.config.constants.AppConfigConstants;

@SpringBootConfiguration
@ConditionalOnAppConfigClientEnabled
//@EnableConfigurationProperties
public class AppConfigClientBootstrapConfiguration {

    protected static final Logger logger = LoggerFactory.getLogger(AppConfigClientBootstrapConfiguration.class);

    public AppConfigClientBootstrapConfiguration() {;
    }

//    @Bean
//    @ConfigurationProperties(prefix = SystemPropertiesConstants.Zodiac.SPRING_BOOTSTRAP_CONFIG_PREFIX, ignoreInvalidFields = true)
//    protected HttpAppConfigClientProperties configClientProperties() {
//        HttpAppConfigClientProperties client = new HttpAppConfigClientProperties(this.environment);
//        return client;
//    }

    @Bean
    @Primary
    @ConditionalOnMissingBean
    //@ConditionalOnProperty(value = SystemPropertiesConstants.Zodiac.SPRING_BOOTSTRAP_CONFIG_ENABLED, havingValue = "true")
    protected CompositeAppPropertySourceLocator compositeAppPropertySourceLocator(ObjectProvider> locatorsProvider) {
        CompositeAppPropertySourceLocator locator = new CompositeAppPropertySourceLocator(locatorsProvider.getIfAvailable());
        return locator;
    }

    @SpringBootConfiguration
    @ConditionalOnAppConfigClientEnabled
    @EnableRetry(proxyTargetClass = true)
    //@EnableConfigurationProperties(ConfigRetryProperties.class)
    @Import(value = {org.springframework.boot.autoconfigure.aop.AopAutoConfiguration.class})
    @ConditionalOnProperty(value = SystemPropertiesConstants.Zodiac.SPRING_BOOTSTRAP_CONFIG_CLIENT_FAIL_FAST, havingValue = "true")
    @ConditionalOnClass(value = {org.springframework.retry.annotation.Retryable.class, org.aspectj.lang.annotation.Aspect.class, org.springframework.boot.autoconfigure.aop.AopAutoConfiguration.class})
    protected static class RetryConfiguration {

        @Bean
        @ConditionalOnMissingBean
        @ConfigurationProperties(prefix = SystemPropertiesConstants.Zodiac.SPRING_BOOTSTRAP_CONFIG_CLIENT_RETRY_PREFIX, ignoreInvalidFields = true)
        protected AppConfigClientRetryProperties configClientRetryProperties() {
            return new AppConfigClientRetryProperties();
        }

        @Bean(name = AppConfigConstants.REMOTE_SERVER_RETRY_INTERCEPTOR_BEAM_NAME)
        @ConditionalOnMissingBean(name = AppConfigConstants.REMOTE_SERVER_RETRY_INTERCEPTOR_BEAM_NAME)
        protected RetryOperationsInterceptor remoteServerRetryInterceptor(AppConfigClientRetryProperties properties) {
            AppConfigClientBootstrapConfiguration.logger.info("{}: Changing backOffOptions to initial: {}, multiplier: {}, maxInterval: {} .And maxAttempts: {} .",
                Constants.Zodiac.CONFIG_SERVER_RETRY_INTERCEPTOR_BEAN_NAME, properties.getInitialInterval(),
                properties.getMultiplier(), properties.getMaxInterval(),
                properties.getMaxAttempts());
            return RetryInterceptorBuilder.stateless().backOffOptions(properties.getInitialInterval(),
                properties.getMultiplier(), properties.getMaxInterval()).maxAttempts(properties.getMaxAttempts())
                .build();
        }

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy