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

org.zodiac.autoconfigure.config.AppConfigRetryAutoConfiguration Maven / Gradle / Ivy

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

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.retry.interceptor.RetryInterceptorBuilder;
import org.springframework.retry.interceptor.RetryOperationsInterceptor;
import org.zodiac.commons.constants.Constants;
import org.zodiac.commons.constants.SystemPropertiesConstants;

@SpringBootConfiguration
public class AppConfigRetryAutoConfiguration {

    protected final Logger log = LoggerFactory.getLogger(getClass());

    public AppConfigRetryAutoConfiguration() {
        log.info("{} loaded.", getClass().getCanonicalName());
    }

    @Bean
    @ConditionalOnMissingBean
    @ConfigurationProperties(prefix = SystemPropertiesConstants.Zodiac.SPRING_CONFIG_RETRY_PREFIX, ignoreInvalidFields = true)
    protected AppConfigRetryProperties appConfigRetryProperties() {
        return new AppConfigRetryProperties();
    }

    @Bean(name = Constants.Zodiac.CONFIG_SERVER_RETRY_INTERCEPTOR_BEAN_NAME)
    @ConditionalOnMissingBean(name = Constants.Zodiac.CONFIG_SERVER_RETRY_INTERCEPTOR_BEAN_NAME)
    protected RetryOperationsInterceptor configServerRetryInterceptor(AppConfigRetryProperties appConfigRetryProperties) {
        log.info("{}: Changing backOffOptions to initial: {}, multiplier: {}, maxInterval: {} .And maxAttempts: {} .",
            Constants.Zodiac.CONFIG_SERVER_RETRY_INTERCEPTOR_BEAN_NAME, appConfigRetryProperties.getInitialInterval(),
            appConfigRetryProperties.getMultiplier(), appConfigRetryProperties.getMaxInterval(),
            appConfigRetryProperties.getMaxAttempts());
        return RetryInterceptorBuilder.stateless().backOffOptions(appConfigRetryProperties.getInitialInterval(),
            appConfigRetryProperties.getMultiplier(), appConfigRetryProperties.getMaxInterval())
            .maxAttempts(appConfigRetryProperties.getMaxAttempts()).build();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy