Pradeep
Pradeep

Reputation: 173

How to update multiple spring config instance clients

Spring cloud config client helps to change the properties in run time. Below are 2 ways to do that

  1. Update GIT repository and hit /refresh in the client application to get the latest values
  2. Update the client directly by posting the update to /env and then /refresh

Problem here in both the approaches is that there could be multiple instances of client application running in cloud foundry and above rest calls will reach any one of the instances leaving application in inconsistent state

Eg. POST to /env could hit instance 1 and leaves instance 2 with old data.

One solution I could think of is to continuously hit these end points "n" times using for loop just to make sure all instance will be updated but it is a crude solution. Do any body have better solution for this?

Note: We are deploying our application in private PCF environment.

Upvotes: 5

Views: 2642

Answers (2)

j.min
j.min

Reputation: 9

Spring Cloud Config Server Not Refreshing

see org.springframework.cloud.bootstrap.config.RefreshEndpoint code here:

public synchronized String[] refresh() {
Map<String, Object> before = extract(context.getEnvironment()
        .getPropertySources());
addConfigFilesToEnvironment();
Set<String> keys = changes(before,
        extract(context.getEnvironment().getPropertySources())).keySet();
scope.refreshAll();
if (keys.isEmpty()) {
    return new String[0];
}
context.publishEvent(new EnvironmentChangeEvent(keys));
return keys.toArray(new String[keys.size()]);

}

that means /refresh endpoint pull git first and then refresh catch,and public a environmentChangeEvent,so we can customer the code like this.

Upvotes: -1

Dave Syer
Dave Syer

Reputation: 58124

The canonical solution for that problem is the Spring Cloud Bus. If your apps are bound to a RabbitMQ service and they have the bus on the classpath there will be additional endpoints /bus/env and /bus/refresh that broadcast the messages to all instances. See docs for more details.

Upvotes: 7

Related Questions