iychche
iychche

Reputation: 11

Spring Config-Client doesn't refresh if Config-Server is down during initial startup

I am running a test with a barebones Spring cloud config-server and a client-application. I executed a refresh scenario (by calling /refresh endpoint on the client-application) after config-server was down initially. Here is what I found

In the second usecase

At this point it looks like /refresh doesn't work if the client-application comes up initially without being able to successfully connect to config-server. I am doing this to test a fallback strategy for the client-application if config-server is not reachable when the client-application is starting up. (The fallback strategy is to have locally packaged properties that will be used if config-server is not available on startup. If the config-server is available then the local properties are overriden). Any pointers to why this is not working and what I could do differently? Thanks in advance.

Edit

Server-Code

@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }
}

Client-Code

@RestController
@RefreshScope
@Component
public class Greeter {
    @Value("${message.greeting}")
    String greeting;

    @RequestMapping(value = "/",produces = "application/json")
    public List<String> index(){
        List<String> env = Arrays.asList("message.greeting: " + greeting);
        return env;
    }

}

bootstrap.yml (On config-client application)

spring:
  application:
    name: configclient
  cloud:
    config:
      uri: http://localhost:8888
management:
  security:
    enabled: false
logging:
  config: classpath:logback.xml
server:
  port: 8000

application.yml

message:
  greeting: Hello from Local!

Config in Git (Served through config-server)

message:
  greeting: Hello from Git-Edited!

Upvotes: 1

Views: 3365

Answers (1)

aksss
aksss

Reputation: 333

According to spring-cloud-config documentation -

If you expect that the config server may occasionally be unavailable when your app starts, you can ask it to keep trying after a failure. First you need to set spring.cloud.config.failFast=true, and then you need to add spring-retry and spring-boot-starter-aop to your classpath. The default behaviour is to retry 6 times with an initial backoff interval of 1000ms and an exponential multiplier of 1.1 for subsequent backoffs. You can configure these properties (and others) using spring.cloud.config.retry.* configuration properties.

Reference -> http://cloud.spring.io/spring-cloud-static/spring-cloud-config/1.3.1.RELEASE/

Upvotes: 2

Related Questions