An important part of a microservice is the need to properly configure it when deployed. Different deployment scenarios will need different configurations. Most applications need to be configured based on a running environment. So it must be possible to modify configuration information from outside of the application so that the application itself does not need to be repackaged. So when writing your microservice, you need a reliable, simple, and standard way to get the configuration into your implementation at runtime.

As part of the work in the Eclipse MicroProfile project, a specification was developed to define a standard way to get your configuration information in your microservice implementation. This is the Eclipse MicroProfile Config specification introduced in MicroProfile 1.1.

The Eclipse MicroProfile Config specification is based upon the Contexts and Dependency Injection (CDI) specification and supports using dependency injection to inject configuration information into your microservice implementation.

Sources of configuration information

Configuration information for your microservice can come from different locations and come in different formats. For example, system properties and environment variables are commonly used as properties files or resources, XML files or resources, and even data sources such as a database. In the Eclipse MicroProfile Config specification, these sources of configuration data are called ConfigSources. All implementations of Eclipse MicroProfile Config, such as the implementation included in Open Liberty, support the required ConfigSources of the system properties, the environment variables, and the properties resource META-INF/ found on the classpath of the microservice implementation.

Since the same configuration property could be defined in multiple ConfigSources, a prioritization can be used to determine which ConfigSource is used for the configuration property value. The default prioritization has system properties before environment variables before the properties resource META-INF/ This means you can supply some default configuration in the properties resource META-INF/ packages with your microservice implementation. Then the system properties and environment variables can be used to replace some or all of the configuration with more specific configuration for the current deployment of your microservice implementation.

Sometimes configuration information can change dynamically. Microservice implementations need to be able to access the latest configuration information without the need to be restarted. This is particularly important for microservices running in a cloud environment. Eclipse MicroProfile Config supports configuration information that can be dynamically updated.

Type safety of configuration information

While ConfigSources supply configuration values as strings, your microservice implementation will often need your configuration information in data types other than string. The Eclipse MicroProfile Config specification supports converters that convert string values to many standard Java™ types, including all the primitives and their wrapper types, a number of time-based types and URL.

Your microservice implementation can also provide custom converters to handle conversion to any types not already covered by the required converters.

We have created a new developer pattern titled “Configure your app using Eclipse MicroProfile Config” to help get you started with Eclipse MicroProfile Config. And if you have ideas on enhancements to Eclipse MicroProfile Config, get involved with the Eclipse MicroProfile community and suggest them.

Join The Discussion

Your email address will not be published. Required fields are marked *