2
votes

When I change a value from my properties repository and restart the Spring Cloud Config Server, the changes do not reflect on it's consumers.

my-microservice/application.properties:

spring.application.name=my-service
spring.cloud.config.uri=http://localhost:8888

MyServiceController.java

@RestController
public class MyServiceController {

    @Autowired
    private Configuration configuration;

    @GetMapping("/my-service")
    public MyServiceBean retrieveMyServiceProperties() {
        // show propertie's values
        return new MyServiceBean(configuration.getPropertie1(), configuration.getPropertie2());
    }

}

spring-cloud-config-server/application.properties

server.port=8888
spring.application.name=spring-cloud-config-server

spring.cloud.config.server.git.uri=file://path

Git repo

my-service.properties

my-service.propertie1=1
my-service.propertie2=2

When I send a GET request to localhost:8080/my-service, that's the result I got:

{  
   "propertie1":1,
   "propertie2":2
}

Fine, that's OK! But, if I change the my-service.properties and restart my Spring Cloud Config Server, the changes do not reflect MyServiceController. I do need to restart my-microservice application, for changes to take effect. Is this the normal behavior? I mean, if this is remote, then, it should be configured whether to cache or not.

2
you shouldn't restart config server, but call the /refresh actuator endpoint on the clientspencergibb
Worked! Thank you.Matheus Cirillo

2 Answers

2
votes

In order to update the configurations, I sent a POST request to localhost:8080/actuator/refresh.

By default, /refresh isn't exposed in actuator endpoints.

I did exposed with the following line in application.properties:

management.endpoints.web.exposure.include=*

Then, sent a POST request with no body to the endpoint above.

1
votes

To update your client application, It's better to use a message broker like RabbitMQ or Apache Kafka. This process has three levels:

  1. The client application and config server subscribe to a specific topic (/refresh) in the message broker.

  2. The config server sends refresh event to that topic (/refresh), as soon as it gets updated. (for example application.properties file gets updated in git).

  3. All client applications are listening to refresh event, when they get refresh message, they will be updated

In brief, we can use the pub-sub model for updating our client applications.

Config Server using Spring Cloud Config and Apache Kafka

Spring cloud config workflow