My web application has several integrations with external systems and all these integration Rest URLs are kept in a config file with in web app. My application reads this config file at start up and use the URL values while making connections to external systems. But quite often it happens that one of the external systems is down and we have to use an alternate URL. In that case, we typically will have to modify the config and redeploy the war file. Is there a way to modify config file with new value without going through a redeployment of the war file?
Asked
Active
Viewed 1,456 times
1
-
It sounds like what you really should look for is the *circuit breaker* pattern. – chrylis -cautiouslyoptimistic- Feb 18 '19 at 04:25
-
1put your config file in a specific location and start your app server with -Dmyweb.config.file=
, and read the file path from the system properties "myweb.config.file", you can change the config at anytime you want – C Chai Feb 18 '19 at 04:29 -
Can't you load balance the requests across those 2 endpoints? Which application server are you using? If you are using Spring then check : https://stackoverflow.com/questions/14117117/dynamically-loading-properties-file-using-spring. I think it will better to have a solution so that the application can intelligently reroute the requests instead of loading a property file. You can use a client side or server side discovery pattern, check service discovery using Eureka: https://spring.io/blog/2015/01/20/microservice-registration-and-discovery-with-spring-cloud-and-netflix-s-eureka – Rahul Feb 18 '19 at 05:25
-
Please add some more details on your setup,like if you are using Spring , Spring-boot , etc. Also , it might be useful to look into Service Discovery pattern. It can also be as simple as implementing a simple DNS type of service if you do not want to use a full blown architectural framework like Eureka , the purpose of the service would be to resolve the right endpoint by simply calling OPTIONS first on the first backend service and if it fails then call OPTIONS on second backend service and return that if it succeeds. Ofcourse , your config should have both endpoint configurations. – fatcook Feb 18 '19 at 06:13
1 Answers
1
In my projects i usually work with Apache Commons Configuration for the management of config files (properties). This library has the capability of automatic reload the values when file changes.
This is muy suggestion of implementation:
Create a class "MyAppConfigProperties" for load the properties file and read your configuration keys:
public class MyAppConfig {
//Apache Commons library object
private PropertiesConfiguration configFile;
private void init() {
try {
//Load the file
configFile = new PropertiesConfiguration(
MyAppConfig.class.getClassLoader().getResource("configFile.properties"));
// Create refresh strategy with "FileChangedReloadingStrategy"
FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy();
fileChangedReloadingStrategy.setRefreshDelay(1000);
configFile.setReloadingStrategy(fileChangedReloadingStrategy);
} catch (ConfigurationException e) {
//Manage the exception
}
}
/**
* Constructor por defecto.
*/
public MyAppConfig() {
super();
init();
}
public String getKey(final String key) {
try {
if (configFile.containsKey(key)) {
return configFile.getString(key);
} else {
return null;
}
} catch (ConversionException e) {
//Manage Exception
}
}
}
Now you have to construct a instance of this class (singleton) and use it in all places in that you need to reed a config key.
Every time you use the method "getKey" you will get the last value of the key without deploy and restart.

JosemyAB
- 387
- 3
- 9