Handling Configuration Properties in Mule ESB


In this tutorial, we will see how to use properties in Mule applications so they can be easily moved between environments and how to segregate the common configuration to a global file.

The video demonstration is available on the youtube, here is the embedded video.

Let's define an environment property value in mule-app.properties, Open the mule project and in mule-app.properties located in the src/main/app folder and define a property called env and set it to DEV then Save the file.
Right-click the src/main/resources folder in the Package Explorer and select New > File.
Set the file name to CRUD-DEV.properties and click Finish.
Then add the configuration values as shown below,
Right-click the project folder in the Package Explorer and select New > Mule Configuration File. Set the file name to Globalconfig and click Finish.
Once the globalconfig file is created, open both globalconfig.xml and muledj.restapiops.crud.xml files in XML configuration view. Now, select the HTTP config and Generic DB config entries in muledj.restapiops.crud file and move it to globalconfig file as shown below,
Return to the Global Elements view in globalconfig.xml. Click on Create and choose Property Placeholder then in the Global Element Properties dialog box, change the location to CRUD-${env}.properties

In global-config file the common connector configurations are available. Now edit both HTTP and database configuration to parameterize the values as shown below.

Return to the Message Flow view in muledj.restapiops.crud.xml and run the project.
In Postman, make a request http://localhost:8888/CRUDDept/FetchDept and confirm you still get data, then return to Anypoint Studio and stop the project.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.