javaspring-bootspring-cloud-configspring-cloud-config-serverspring-cloud-config-client

Refreshing configurations of microservices based on messaging topic


I have a spring cloud configserver in place and we are using s3 as a version control.
I have activemq for sending topics which will later be consumed by the microservices. Now we need to refresh the configuration of microservices depending upon the value of the topic which we send in activemq.
Lets say we only need to refresh the configs of the microservice only when we see a value 'REFRESH' in the topic, otherwise no change.
Also we do nt want to call the actuator /refresh ,/monitor or /busrefresh endpoint to refresh the configs because we need to reload based on the topic value.


Solution

  • After few retries i came up the solution and it is working as expected. what we need to do first is to add actuators dependency.

    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
    

    Now in the application.properties we need to enable below property so that actuator can perform the restart.

    management.endpoint.restart.enabled=true
    

    Now finally we need to call the restart method from RestartEndpoint class so that it can restart our application.

    @Autowire
    RestartEndpoint restartEndpoint;
    
    public void reloadConfigs(){
        restartEndpoint.restart();
    }
    

    Please give suggestion if solution require any improvement.