Faridabad MuleSoft Meetup 05 March 2022 - Transaction Management in MuleSoft
Event link: https://meetups.mulesoft.com/events/d...
Agenda:
What is Transaction and how to Manage in MuleSoft:
Transaction Types:
Transactional Actions and C
2. 2
1. Introductions
2.Transaction in MuleSoft
3.Managing transactions in Mule applications
4.Demarcate transaction boundaries in Mule applications
5.Identify resources that participate in transactions in Mule Applications
6.Demo
7.Managing transactions using the Saga pattern (Overview)
8.Quiz
9.Networking time
10.Next Event Announcement
Agenda
3. 3
●About the organizer:
○ Amit Singh
○ Pankaj Goyal
●About the speaker:
○ Gaza Nand
Introductions
A SHOW OF HANDS:
Who is new to this Meetup?
4. 4
About the speaker:
○ Gaza Nand
Introductions
A SHOW OF HANDS:
Who is new to this Meetup?
6. 6
● In its narrow technical definition, a transaction is a grouping of operations that are guaranteed to all complete, or none
at all.
- Transaction implementation should achieve below ACID properties.
Atomicity : All changes to data are performed as if they are a single operation/unbreakable unit.
Consistency :Data is in a consistent state when a transaction starts and when it ends. Data integrity should be maintained.
Isolation : The intermediate state of a transaction is invisible to other transactions and each TX should be isolate.
Durability: After a transaction successfully completes, changes to data persist and are not undone.
Transaction in MuleSoft
● Transactions Category
- Automate ( Handled by Mulesoft )
- Manual (Handled by Customer ) Saga
Pattern
Local and
XA
● Transactions are operations in a Mule application for which the result cannot remain
indeterminate. In other words, where a series of steps in flow must succeed or fail as
one unit.
7. 7
● Local Transaction
○ For example, a series of operations to one database connection
● Global (XA) Transaction
○ For example, a series of operations to one A series of operations between one or more (typically two) different (XA compatible) systems, such as two
different databases, or a database and a JMS server
Transaction Types
Local Transaction XA Transaction
Spanning across single resource Spanning across Multiple resource
All Operation must belong to same module Operations can belong to the same as well
different connectors.Based on 2PC algorithm
All connectors should use single config-ref Valid only on supported resources
Does not support nested Transactions Supports nested Transactions
8. 8
● Database Module
○ All Operations
Transaction Supported Components/Modules
● JMS Module
○ On New Message
○ Publish
○ Consume
● VM Module
○ Listener
○ Publish
○ Consume
○ Publish consume
● TRY Scope
9. 9
● Flow Level ( Event Source Level )
A transactional connector acting as an event source.
○ DB - On Table Row
○ VM - Listener
○ JMS - On New Message
Demarcating the beginning of a transaction
● Scope Level ( Processor Level)
○ Try Scope
10. 10
Committed automatically at end of a
○ Flow
○ Try scope
○ On Error Continue scope
Demarcating the end of a transaction
● Rollback transaction
○ After a failure occurs in a transaction scope, but only if the error is
not handled in an On Error Continue scope.
○ On Error Propagate scope.
○ By throwing an error in a flow or in a Try scope using <raise-error>
11. 11
Transactional Actions
Action Description Processor supports
ALWAYS_BEGIN Always start new TX Throw
exception if TX ongoing
JMS, VM and DB connectors
(listeners only) and Try scope
ALWAYS_JOIN Always participate in ongoing
TX Throw exception if no
ongoing TX
JMS, VM and DB connectors (non-
listeners operations)
BEGIN_OR_JOIN Participate in ongoing TX Start
new TX if no ongoing TX
Try scope
JOIN_IF_POSSIBLE Participate in ongoing TX Do
not start a new TX if no
ongoing TX
JMS, VM, and DB connectors (non-
listeners operations)
INDIFFERENT Never participate in TX Ignore
any ongoing TX
Try scope
NONE Do not initiate a transaction. JMS, VM, and DB connectors
(listeners only)
Not Supported Execute outside any existent
transaction. It does not have
transactional behavior.
Operations that support transactions
A Transactional Action defines the type of action that operations take regarding transactions.
12. 12
● Bitronix Transaction Manager allows Mule to automatically recover interrupted transactions
on restart.
● Bitronix is available as the XA transaction manager for Mule applications.
● To use Bitronix, declare it as a global configuration element in the Mule application.
● Each Mule runtime can have only one instance of a Bitronix transaction manager, which is
shared by all Mule applications.
● For customer-hosted deployments, define the XA transaction manager in a Mule domain
– Then share this global element among all Mule applications in the Mule runtime
Transaction Manager (Bitronix)
15. 15
● Saga pattern is an alternative to XA when resources are not XA-capable or XA is undesired.
○ For instance, API invocations
○ A way to achieve reliability that does not have ACID guarantees
Managing transactions using the Saga pattern
● Features of the Saga pattern include
○ Maintains consistency (but not atomicity) across multiple services without requiring a
transaction manager system
○ Uses a sequence of local TXs
○ Failure of a local TX executes a series of compensating transactions to undo the previous
successful TXs
○ More complex programming model compared with XA resources
16. 16
● Event/Choreography pattern.
○ The service executes the transaction (TX) and publishes an event to be used by the next service
Types to implement Saga patterns
● Orchestration pattern
○ Saga orchestrator communicates with each service using a reply style.
○ The orchestrator logic can be modeled as a state machine
○ Similar to an XA pattern, the orchestrator coordinates transactions
• But does not require an XA-capable transaction manager nor resource managers.
20. 1) VM,DB,AMQ
2) JMS,DB,FILE
3) DB,JMS,VM
4) JMS,VM,HTTP
What are different types of Transaction
Supported Components/Modules in MuleSoft
21. 1) Dedicated
2) GRIZZLY
3) UBER
4) All of Above
What is the default Mule Runtime (scheduler
pool) thread pool type after 4.3.X version used
for mule application.
22. 1) Single Resource and eXtended Architecture
2) Automate and Manual
3) Orchestration and Orchestration pattern
4) All of above
What type of transactions are handled by
MuleSoft only.
24. 1) YES
2) NO
When Async scope running within a
transaction, if any error produced inside an
Async scope does it result in a rollback.
25. 25
● Be a Helping Hand
○ Contact the Meetup Organizers if you want to be Speaker in upcoming events
○ Use https://meetups.mulesoft.com/faridabad/ link to contact to Organizers
● Share:
○ Tweet using the hashtag #MuleSoftMeetups #FaridabadMeetup #MuleSoft
#MuleMeetup
○ Invite your network to join: https://meetups.mulesoft.com/faridabad/
● Feedback:
○ Fill out the survey feedback and suggest topics for upcoming events
○ Contact MuleSoft at meetups@mulesoft.com for ways to improve the program
What’s next?