What exactly is Mirth’s configuration map? And how should Mirth developers take advantage of it to create more maintainable channels?
Before diving in, it should be established that the configuration map has some key differences from the other maps that you may have worked with. The configuration map functions as a map in the same manner as the others but has some of its own nuances that you should be aware of.
The purpose of the configuration map is to store relatively static key-value pairs that could be used in multiple places of your Mirth instance.
What do I mean by relatively static? Key-value pairs in the configuration map should not be changing very often. For example, a database connection string should not be constantly changing. This makes the configuration map a good place to store this data.
Additionally, there is a good chance that a database connection string will be used by multiple channels in your Mirth instance. This is another reason for Mirth developers to store a database connection string in the configuration map.
One major way that the configuration map differs from the other maps is in how the data is stored. All of the other maps are stored in memory while the configuration map’s contents are contained in a properties file in the Mirth installation.
Practically, this difference won’t affect developers; however, it’s good to know in the event that you ever have to do some maintenance on the Mirth installation itself.
Building the Configuration Map
Mirth developers build the configuration map differently than other maps. In fact, the configuration map exists in Mirth Connect Administrator’s graphical user interface (GUI).
After you log into Mirth Connect’s Administrator, navigate to Settings.
Select the Configuration Map tab.
Below the tab bar you will see the configuration map with all its values.
You can see that the table has the key name, the value, and then any comments regarding that key-value pair. If you need to add a key-value click ‘Add’ on the top-right hand side.
Immediately you should see a new entry appear at the bottom of the table.
Click inside the key cell and populate the key. Afterward, you can do the same for the value and comments if you wish. Once you are done, make sure to click ‘Save’ on the left-hand side.
You can also remove an entry from the configuration map. Simply select the entry and click ‘Remove’ on the right-hand side.
As you’re working with the configuration map, you can check the ‘Show Values’ checkbox which will display the content of the ‘Value’ column.
Accessing the Configuration Map
You should notice that the syntax is identical to accessing other maps in Mirth. The only difference is that the configurationMap reference is used.
Utilizing the configuration map allows developers to keep their code the same even if values in the configuration map change from time to time, which is definitely possible.
For example, say that you used the configuration map to store a database connection string. At some point in the future, if the database server changes, you can simply change its value in Settings without having to alter your channel at all. Once you save the value, Mirth will automatically update the properties file behind the scenes.
It should be noted that developers should not need to access the configuration map all too often in their code. You should only use the configuration map occasionally for data points that are relatively static and need to be accessed in multiple places.
Nevertheless, any Mirth professional should be knowledgeable about the configuration map as a tool in their development arsenal.