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
- Require to Add Actuator Dependency, [Spring Cloud Dependency, and DependencyManager]
- 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.
- 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 👍
0 Comments