Injecting Environment Specific Variables Dynamically in WSO2 MI

Prabod Dunuwila
1 min readNov 27, 2024

--

This article is based on WSO2 MI 4.1.0 and I’m going to discuss about,

  • How to maintain environment specific variables
  • Read properties at runtime

How to maintain environment specific variables

To use different properties files for different environments (e.g: dev.properties, prod.properties) instead of the default file.properties file, set the file path in the startup script by using the properties.file.path system property. The path should point to the absolute path of the directory where the properties file is stored. For example, if dev.properties is in the default <MI_HOME>/conf/ directory,
-Dproperties.file.path=<MI_HOME>/conf/dev.properties \

Then the WSO2 MI will load parameters from dev.properties during startup, allowing for environment specific configurations without changing the synapse artifact.

Read properties at runtime

If you want to read the properties defined in the properties file which are modified at the runtime, you can follow the below steps.

1. Open to the <MI-HOME>/bin/micro-integrator.sh file.
2. Add the below highlighted configuration in the ‘micro-integrator.sh’ file.
-Dfile.properties.sync.interval=10 \

3. In the mediations, if you need to update it during the runtime you will need to define a property with the file scope and use that value as in the below example,

<property name="ep_url" expression="get-property('file','stockQuoteEP)"/>

And when you modify the properties (For example stockQuoteEP in the above scenario) in the <MI-HOME>/conf/file.properties (or the other custom property file as defined in the micro-integrator.sh for -Dproperties.file.path) it will reload the properties in file.properties file periodically according to the defined time interval.

--

--

Prabod Dunuwila
Prabod Dunuwila

Written by Prabod Dunuwila

Software Engineer @ WSO2 | MIT @ University of Kelaniya, Sri Lanka.

No responses yet