Search code examples
javaspringspring-bootkotlinspring-cloud

How set up retry config fetching in spring boot?


I have config server and application fetches configs from this server. I want to set up retry mechanism of fetching. If config server is unavailable application shall sent requests for 10 minutes.

In spring docs i found next configs

spring.cloud.config.uri=http://localhost:9090
spring.cloud.config.fail-fast=true
spring.cloud.config.retry.max-interval=10000
spring.cloud.config.retry.max-attempts=2000

But they change nothing. My app doesn't do retry requests it just fails with

Caused by: java.net.ConnectException: Connection refused: connect 

(Config server is down in that moment)

What am i doing wrong? There is way solve my problem?


Solution

  • I solved my problem by adding next @Bean to context

    @Bean
        public RetryOperationsInterceptor configServerRetryInterceptor(RetryProperties properties) {
            return RetryInterceptorBuilder
                    .stateless()
                    .backOffOptions(properties.getInitialInterval(),
                            properties.getMultiplier(),
                            properties.getMaxInterval())
                    .maxAttempts(properties.getMaxAttempts()).build();
        }