Issue
I need to implement this scenario into a SpringBoot microservice:
In order to support multiple business logic that are based on different configurations for each supported logic, I would like to use a dynamic configuration set.
As an idea, suppose that it's necessary to support a lot of different configurations where each configuration presents the same set of parameters with, obviously, different values.
I'm just able to image this as json, something like this:
{
"configurations": [{
"client": "client_1",
"parameterA": "x",
"parameterB": "y",
"parameterC": "z"
},
{
"client": "client_2",
"parameterA": "x2",
"parameterB": "y2",
"parameterC": "z2"
},
{
"client": "client_3",
"parameterA": "x3",
"parameterB": "y3",
"parameterC": "z3"
},
...
]
}
Suppose that I'll put this json into my project. When the service starts, the json config file will be loaded in order to load the configurations list in memory. The idea is to create a custom @Configuration
in order to have some utility methods to read the configurations values (eg. getConfigurationByClient
).
Do you think that this could be a good way?
Are there some different best practices to implement similar requirements?
I'm not able to find similar examples or articles in order to understand if this could be a good approach.
Solution
I would suggest it depends on frequency of this values getting changed. If frequency is too low, and you are okay with deploying your entire application to change some of the values, then it's fine I guess to keep json in your project.
But if you have some requirement to change it every month or in some interval, I would suggest to have this file at remote location and have service pull json(not feasible for low latency if associated to some REST endpoint) and load it in your service to do following task.
Other better approach would be to persist it in DB (RDBMS table etc), where you can change this values directly and app service can query the latest param values from DB and perform the bussiness logic.
Answered By - Murtuza Vadharia
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)