Microservice Configuration

Parameters like password, db connection data, dev parameters, test parameters etc should be maintained in a separately called configuration. This is possible by maintaining .yml file or .properties file.

  1. .properties file contains the key value pairs and are accessed in the microservice by @Value(“$key”) annotation before a variable declaration.
  2. .yml file also stores key value pairs. It can have tree structure to avoid long prefixes.
  3. @ConfigurationParameter(“prefix”) annotation is used to fetch all the parameters in config file with that prefix and stores in variables of a bean class.
  4. But, all these go to the jar file, so config is not externalised. We can achieve externalisation by having a copy of the config file at the same directory of jar. This will override the internal config file. We can mention the parameters as command line arguments.
  5. application-test.yml goes to test env, application-dev.yml goes to dev env otherwise takes the default.
  6. Commit the changes in config file to git for version management or we can use SVN or HashiCorp.
  7. Real time monitoring is done by Spring Cloud Config Server and Spring Cloud Config Client. Add the dependency and arcade dependency too.
  8. Spring Cloud Config Server will have interact with git and fetches the latest config properties and exposes an endpoint http://localhost:8200/application/default or http://localhost:8200/application/dev or http://localhost:8200/application/test to view the parameters depending on the environment. We need to mention the port in this microservice.
  9. Spring Cloud Config Client must be added to pick up the changes from Spring Cloud Config Server. It exposes /refresh endpoint. After making a request to this endpoint, we can have real-time update in parameters in the application without restart.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store