Skip to content

MOSIP Configuration Server

gurpreet.bagga edited this page Jul 12, 2019 · 17 revisions

MOSIP Configuration Server

We will be using MOSIP config server (Spring cloud configuration Server) to manage configurations of all the services.

NOTE: For the documentation purpose I have mentioned the config server URL as http://localhost:8080 in this document, but you have to mention the URL where configuration server is running.

Configuration Server

Git Repo

  1. All the configuration files at the moment are stored inside git in
    (can be customized to take it from git repo of system owner. Change property in config server accordingly.)
  2. For every module (specific to an environment such as dev, qa, test etc.) there will be a single property file (eg: for kernel)
    The nomenclature will be as follows:
    For example if the application name is kernel and microservice is kernel-idgenerator-vid and profile name can be dev(to differentiate between different environments, eg: testing, dev, qa etc.), so the properties file name will be:
  3. If we are using multiple profiles, say one for dev and one for testing, we can create 2 properties files with names -,, and can switch between multiple profiles through Microservice application.
  4. Properties common across the modules will be stored in files named: application-{profile-name}.properties
  5. For XML files, name them as follows:

Microservices Configuration Clients:

Spring boot client

All the microservices will act as clients and reuqest configuration from config server.

  1. Microservices should include spring-cloud-starter-config dependency, which can be added through maven in their pom.xml.


For actuators refresh endpoint (to refresh properties at runtime) we need actuator dependency in client

2. There should be one file in the spring boot application(microservice) under resources which will contain the details for MOSIP config server. Inside the properties file following properties have to be mentioned:

  • key with the value of URL of config server that will be provided.
  • which will define the branch from which we have to get properties from.
  • which will contain the value of profile to be activated (Eg. dev for dev profile, when filename is, and test for test profile when filename is
  • which is the folder inside git repo which contains the configuration files.
  • name of the application/microservice
  • name of module to which the microservice belongs (eg. Kernel, Pre-Registration)

Sample file:

#Port where the application needs to run
server.port = 8081
# Application name - the name appended at starting of file name to differentiate
# between different property files for different microservices

#Active Profile - will relate to development properties file in the server.
#If this property is absent then default profile will be activated which is
#the property file without any environment name at the end.

# defining current branch in which we are working as label

# url where spring cloud config server is running

#exposing refresh endpoint so that whenevr configuration changes in git,
#post /actuator/refresh endpoint can be called for the client microservices
#to update the configuration
3. Once the setup is done, the microservice/application will be able to fetch the properties from config server. For Example:

* RefreshScope annotation is used such that all the rest APIs can be updated by calling
* POST /actuator/refresh endpoint whenever configuration files change in git repo.
class MessageRestController {

protected final Log logger = LogFactory.getLog(this.getClass());

@Value("${msg:Hello world - Config Server is not working..pelase check}")
private String msg;

String getMsg() {
return this.msg;

In the above snippet we are using @RefreshScope annotation which will help the client application to get lastest configuration from config server without restarting the application (by calling the refresh API /actuator/refresh on the application endpoint)
4. For any other configuration file such as xml/json etc. you can directly get the entire file through the following url:
http://{mosip-config-server URL}/{} /{label} /{branch}/{filename}.(xml/json).

Vert.x client:

  1. For Vert.x application we need the following dependencies to be added to our Maven project: <dependency>

  2. We will be using **ConfigRetrieverOptions **in Vert.x and set the store type to "spring-config-server" and we will provide configuration for this type, by giving URL in the following format:
    protected Future<Void> readConfig(String hoconConfigPath) {
    Future<Void> future = Future.future();
    / **
    * Adding config options for vert.x application
    ConfigRetrieverOptions options = new ConfigRetrieverOptions();
    options.addStore(new ConfigStoreOptions()
    * Vert.x provides different stores to choose from, right now we are selecting
    * spring-config-server to connect to our server
    * We are providing URL in the following format -
    * <config-server-url>/<application-name-microservicename>/<profile-name>/<branch-name>
    * /
    .setConfig(new JsonObject().put("url", "http://localhost:8080/kernal-kernel-idgenerator-vid/uin/DEV")
    .put("timeout", 10000)));

  3. Once the setup is done we can use the ConfigRetriever class object to fetch the configuration as follows:
    * ConfigRetriever object to retrieve the configuration stored
    ConfigRetriever retriever = ConfigRetriever.create(vertx, options);
    retriever.getConfig(ar -> {
    if (ar.succeeded()) {
    * All the configuration is stored in this configuration object, we can use it anywhere
    * to fetch the values by providing the keys
    this.configuration = ar.result();
    } else {
    LOG.error("Failed to read configuration", ar.cause());;
    return future;

  4. Lets assume I put port number in which the application will be running in the properties file, and I need to get that port value while initiating the application, I can get it as follows:
    Integer port = Integer.parseInt(configuration.getString("port"));
    server = vertx.createHttpServer()
    .requestHandler(req ->
    req.response().end("I am running on the port fetched from the configuration "
    + "stored in Spring config server")).listen(port);

Whenever there is a change in the configuration in GIT Repo, every microservice/application which is using that particular configuration has to call the refresh endpoint in order to get that latest configuration without restarting. If the client doesnt call the refresh API, it will keep on getting the old configuration.
The refresh end point is following:
POST {Microservice-URL} /actuator/refresh

For Encryption and Decryption of properties you need to generate Keystore, For more information look here

To setup and configure keystore for config server refer to the configuration server README (under mosip -> kernel -> kernel-config-server ->

To Encrypt any property:
Run the following command :
curl http://<your-config-server-url>/<config-server-application-context-path-if-any>/encrypt -d <value-to-encrypt>

And place the encrypted value in client application properties file with the format:

To Decrypt any property manually:

curl /<config-server-application-context-path-if-any>/decrypt -d <encrypted-value-to-decrypt>

NOTE There is no need to write decryption mechanism in client applications for encrypted values. They will be automatically decrypted by config server as long as {cipher} is prefixed with encrypted value.

Clone this wiki locally
You can’t perform that action at this time.