Mule 3 Mulesoft Basics Mulesoft Tutorial

Externalizing Common Mule Flows

Externalizing Common Mule Flows


In this tutorial we will be externalizing some common mule flows so they can be used by multiple Mule Applications
For Example – If I have a common exception handling which is same for all my other applications and I want to externalize this common exception handling code so that –
1. No one in the team can modify the common flows leading to code discrepancy.
2. Teams don’t have to copy same code again and again in my next API which they are going to build.
3. Also, This will also help my API code look more neat and clean.

Externalizing common mule flows can be achieved by exporting the flows to be externalized into a JAR file and then importing the JAR in other applications. Tells look on the details of how we can do this with just few steps.

1. Understanding the Flow


In the flow below we want to externalize sub flow – “externalizeMuleAPISub_Flow” which is been called by Flow reference in Get and Post  Flows  and exception handling – “externalizeMuleAPI-apiKitGlobalExceptionMapping”.


2. Creating new Mule project


We need to create a new mule project and dump the mule common flows that we want to externalize into it. And remove copied code from our previous project.

Here we have deleted and added the 2 flows from our old project into our new project.

 

3. Exporting the new project as JAR file.


Here are the steps to be followed to export the project as JAR.

Right Click on the Project in Package Explorer >> Click Export

In the Popup Window Select Java>Jar File and Click Next.

Select The project to be exported “externalflows” and add the path where the JAR is to be saved and Click Finish.

 

Now, we have create the project with common flows as Jar and export it to the specified location.

4. Importing the JAR file


Now after exporting JAR, we need to import it to our main project.

To Import the Jar -> go to Project Properties and Click “Add External Jars” and select the JAR File.

5. Adding the Common Flows


Now we need to add the mule XML file name that we have imported as JAR into our main project.

6. Running the Code


You might see few error been reported by Mule even after adding the mule XML filename. But do not worry on building the application all the error will go off.

Varun Goel

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.

Leave a Reply

Your email address will not be published.