7. Config Server - Reload Updated Configuration from GitHub Properties file Without Restarting Microservice by /refresh actuator

After updating a properties file we can reload that configuration without restarting the micro-services.

Two ways we can achieve this  
By calling /refresh actuator of that microservice. Another is using Cloud Bus.
Using /refresh Actuator: When we update a properties file for any microservice in the GitHub repository, there’s no need to restart the service to apply the new configuration. Simply call the `/refresh` Actuator endpoint, and the microservice will load the latest configuration instantly.

Development Steps
  1. Require to Add Actuator Dependency, [Spring Cloud Dependency, and DependencyManager]
  2. Enable the actuator endpoint in the config-file(employee-service.properties in the GitHub repo).
    management.endpoints.web.exposure.include=*
Test
Add a property and its value in the config-file(employee-service.properties) and create a Test Controller in Employee-Service to get that configuration value as a response. And check by calling the Test Controller before and after changing that property value.
  • Add configuration in employee-service.properties file. Our dummy property name is myName and default value is Roman Sarker. 
  • Create a Test Controller(API) that gets that configuration/property value from GitHub and Response.
    • Add @RefreshScope annotation
    • Take a variable and map with the property name of the configuration file to get the property value using @Value annotation. 
    • Remember that the property-name and value of the @Value annotation must be the same. 
  • Now call that controller to get the existing value.
  • Change the configuration file by modifying the myName value.
  • Call the /refresh actuator of Employee-Service to reload the properties file
  • Now test by calling the Test Controller to get the updated property value.

Summary:
This blog covered how to reload configuration files (properties file in GitHub repo) after modifying without restarting any services using /refresh actuator.

Done 👍

Post a Comment

0 Comments