Mulesoft Tutorial

Externalizing Error Handling and Flows In Mule 4


While building multiple APIs, we might want to export common flows that are used across or global error handling framework that is common for all the APIs. This is helpful incase; any changes to common flow, we need not end up making code changes to all the APIs across.

In this “Externalizing Common Flows In Mule 4” tutorial we will be looking in how we can export common flows/error handling to an external JAR and import them in our APIs.

In the below example we have a flow “commonlogggerFlow” and exception handler “commonExceptionHandler” that is been used across multiple API as is and needs to be externalized.

For externalizing the flows, we need to create a new mule 4 Project and add the flows that we need to externalize in here. In this case we will be adding commonloggerFlow and commonExceptionHandler into new mule 4 project commonFlows.

Once done, then we need to export our new project as Mule 4 Deployable Archive. This will give us a  Mule 4 JAR file that needs to be imported into our projects.
Right click on the Project > Select Export > Select Anypoint Studio to Mule Deployable Archive >  Select path to be exported

Now, in our main project we will import this jar as a maven dependency.
Right click on Project > Mule > Add Maven Dependency > Select the JAR that we have exported.

Above steps will added the jar to local maven repository and also create a dependency in pom.xml

Once we have imported the jar as maven dependency, we need to specify Mule file name present in the JAR in our Mule Project.
Go to Global Elements > Create > Expand Global Configuration > Import

With this configuration we can now refer to common flows or common error handling defined inside the JAR.


About Varun Goel

Varun Goel is a technology enthusiast with 6+ years exp in IT industry. In fact, he is been developing application after schooling as freelancer. Currently working with one of the Fortune’s 100 Companies having vast experience Mule ESB, Tibco, HTML5, CSS, JSS, Android, Core Java, JSP, PHP, MySQL, AutoCAD, Maya, ZBrush, Photoshop, Flash CS and many more.

3 comments

Leave a Reply

Your email address will not be published.