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

The new Gartner Critical Capabilities report explains how APIs and microservices enable digital leaders to deliver better B2B, open banking and mobile projects.

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!

The new Gartner Critical Capabilities for Full Lifecycle API Management report shows how CA Technologies helps digital leaders with their B2B, open banking, and mobile initiatives. Get your copy from CA Technologies.

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 }}