Configurations in Mule ESB
March 1, 2016

Sharing Code and Custom Configurations in Mule ESB

by Marketing in Mulesoft , Tips and Tricks 0 comments

By Sam Kummary

A key principle in software engineering is Don’t Repeat Yourself (DRY).  But how do you accomplish this in Mule development where you don’t have all the features of object-orientation available for sharing code across the various projects in a large solution?

There are two key techniques available in Mule.  First, Domain Projects allow sharing configuration across multiple projects, but they do not support sharing flows.  However, there is another lesser-known technique that can enable you to share flows across projects. This process is outlined below:

First, create a maven-enabled mule project in Anypoint Studio, with a name indicating that it is a common project. The steps below detail the tasks you’ll need to complete:

1. Define or add the flows/sub-flows that need to re-used and referenced from other projects.

2. Add/define custom configurations for end-points such as HTTP, VM Queues, FTP, Databases or other connectors/transformers.

Example – Custom HTTP configuration:

<http:listener-config name=”HTTP_Listener_Configuration” host=”${http.server}” port=”${http.port}” doc:name=”HTTP Listener Configuration”/>”

The usage of ‘host’ and ‘port’ values based on MuleSoft’s documentation on Configuring Properties and Deploying to Multiple Environments.

3. In the pom.xml file of the common project, change the packaging of the project from ‘mule’ which is default, to ‘jar’ ( <packaging>jar</packaging> ). One important thing to check here is to make sure that the pom.xml file contains dependencies for all the components used (such as Database, FTP, HTTP etc).

4. Once this is done, use maven to clean compile the project and install the common project as jar (assembly).

The second part of this is referencing the newly created common jar file in each project’s xml configuration files that need to use the common configurations and shared code. This can be accomplished by the steps below:

1. Add a dependency for the installed common project’s jar file.



2. A reference to the common project’s xml file needs to be made in order to import common properties etc :


<spring:import resource=”classpath:Project_Common.xml”/>

3. Make a reference to the properties earlier defined for the connectors/end-points or transformers. Also, using flow-reference to refer to any flows/sub-flows in the common project works automatically as if a local flow/sub-flow is referenced (otherwise try ‘updating project dependencies’).


In the referencing project, the HTTP configuration can be used as –

<http:listener config-ref=”HTTP_Listener_Configuration” path=”/testCommon” doc:name=”HTTP”/>

Voila!  Code sharing across Mule projects accomplished.


Leave a comment