Over a million developers have joined DZone.

How to Handle Transaction Scope in Mule

DZone's Guide to

How to Handle Transaction Scope in Mule

In this article, we'll learn how to roll back the clock (so to speak) using transaction scope to fix any files giving our application trouble.

· Integration Zone ·
Free Resource

How to Transform Your Business in the Digital Age: Learn how organizations are re-architecting their integration strategy with data-driven app integration for true digital transformation.

Hi Mulies! In this tutorial, we are going to handle Transaction Scope (Roll Back Mechanism). 

Here is a small piece of a Transaction Scope application which I am going to demonstrate below.

Here Is the Flow:

Image title

Here, my use case is to insert a new employee record in two database tables. In Table 1, the employee Education Details are inserted and in Table 2 employee personal data is inserted. So while I am inserting the data of new employees, if I get any errors I need to roll back the information that I had previously inserted in Table 1.

Database 1:

In Database 1, I am inserting employee education details like Name, Graduation Date, Previous Experience, etc.


I'm using a logger to print the number of records inserted in the Database Table.


Here I am using Groovy's sleep function to cause my flow to wait for 20 seconds to check whether the first database is executed correctly or not.

Image title

Database 2:

In Database2, I am inserting employee personal details like Name, Contact Details, etc.

But, while inserting the details, I missed a value, which causes the applicaiton to throw an error like ORA-00947: not enough values. Now I need to roll back the data which had previously been inserted in Database 1.

Application Testing:

Right click on the application and run the project so that if there are no errors in the application it will be deployed successfully.

Image title

You can see above that when the employee's education details are inserted in Table 1 the logger printed that one record had been successfully inserted.

So now the flow is made to sleep for 20 seconds. Later it throws an error due to the reasons I explained above. So now, due to transaction scope in Mule, you can go and check Table 1 for the record that is causing the application to not function and remove it. This is how you can use and work with transaction scope in Mule!

Hope this helps!

Suggest your Feedback 

Thank You!

Make your mark on the industry’s leading annual report. Fill out the State of API Integration 2019 Survey and receive $25 to the Cloud Elements store.

mulesoft ,mule 3.8 ,mule flow ,integration ,transaction scope

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}