XA Transactions

XA transactions let IBM MQ participate in the same global commit decision as your database, message-driven partner, or second queue manager resource. Without XA, you might MQCMIT while Db2 rolls back—money moved in SQL but notification never sent, or message sent twice after ambiguous failure. With XA, a transaction manager runs two-phase commit: prepare asks every resource if it can commit; commit makes all permanent or rollback undoes all. Enterprise Java servers, Spring with XA DataSource, and z/OS RRS/CICS paths implement this for decades. Beginners should know when they are inside global transactions versus local MQ-only syncpoints, what indoubt means in overnight ops pages, and why mixing manual MQCMIT with container XA breaks atomicity. This tutorial explains roles (application, transaction manager, resource manager), two-phase flow, MQ as XA resource, failure and recovery, contrast with local UOW, and mainframe coordination with Db2.

Roles in Distributed Transaction

Application performs business logic and enlists resources. Transaction manager (TM) owns the global transaction ID and drives prepare/commit. Resource managers (RM) include IBM MQ queue manager and Db2. MQ XA interface registers with TM; application rarely calls xa_* directly in modern stacks—containers do enlistment.

Local UOW versus XA global transaction
AspectLocal MQ UOWXA global
CoordinatorMQ queue managerTransaction manager
ParticipantsMQ onlyMQ + Db2 + others
Commit APIMQCMITtm.commit() / container
Failure riskMQ vs DB mismatch if both usedAtomic all-or-nothing
IndoubtRare on single QMRecovery after TM crash

Two-Phase Commit Flow

  1. Begin global transaction.
  2. MQPUT/MQGET and SQL under same transaction.
  3. Prepare: MQ and Db2 vote commit-ready.
  4. Commit: all resources finalize; or rollback all on any failure.
text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Simplified XA flow: App -> TM: begin() App -> MQ: put (enlisted) App -> DB: insert (enlisted) App -> TM: commit() TM -> MQ: prepare -> OK TM -> DB: prepare -> OK TM -> MQ: commit TM -> DB: commit If DB prepare fails: TM -> MQ: rollback TM -> DB: rollback

Explainer: Two Judges Must Agree

XA is two judges who must both say yes before the contest result counts. If one judge says no, the whole competition is cancelled for everyone—even if the other judge already liked your performance.

Java EE and Spring

JMS XA connection factory and JTA UserTransaction enlist MQ. @Transactional on a service method using XA DataSource and JmsTemplate can commit both. Misconfiguration uses non-XA connection—silent split brain. Verify connection factory is XA-enabled in deployment descriptor or Spring config.

z/OS: RRS and CICS

Resource Recovery Services coordinates Db2, MQ, and other RRS-capable resources on LPAR. CICS global transactions include MQ in the task syncpoint when defined. Batch with RRS uses standard mainframe recovery. Operators use ISPF recovery panels and IBM docs for indoubt resolution—not desktop MQCMIT alone.

Indoubt and Recovery

TM crashes after prepare leaves MQ or Db2 indoubt—DISPLAY and recovery utilities show state. Heuristic rollback or commit is last resort with audit. Prevention: stable TM cluster, timeouts, idempotent consumers. Application logs global transaction id when exposed for correlation.

Performance Considerations

Two-phase commit costs more round trips than local MQCMIT. High-throughput fire-and-forget may skip XA intentionally accepting eventual consistency patterns (outbox table, saga). Choose XA when financial atomicity mandates it.

When XA Is Not Used

Saga pattern: local commit MQ, later compensate with reversal message. Outbox: write event row and MQ in one DB transaction without XA by reading outbox poller. Understand compensating actions versus true atomicity.

Troubleshooting

  • Heuristic mixed outcome — operations incident; IBM recovery procedures.
  • Transaction timeout — partial prepare; rollback all.
  • Duplicate after recovery — idempotent design.
  • Manual MQCMIT in XA app — do not mix APIs.

Explain Like I'm Five: XA

XA is when you and your friend both have to press okay on the tablet before the pizza order sends—if one presses cancel, the order is cancelled for both.

Practice Exercises

Exercise 1

Draw prepare/commit sequence for MQ put + SQL insert.

Exercise 2

When would you choose saga over XA for microservices?

Exercise 3

Research how your app server configures XA JMS connection factory.

Frequently Asked Questions

Frequently Asked Questions

Test Your Knowledge

Test Your Knowledge

1. XA coordinates:

  • Multiple resource managers
  • Only one queue
  • Only TCP
  • Only JCL

2. Two-phase commit phase 1 is:

  • Prepare
  • Format disk
  • Start listener
  • DELETE QMGR

3. Indoubt means:

  • Prepared but not finalized
  • Committed
  • Queue empty
  • Channel running

4. Local MQCMIT without XA:

  • Only MQ in UOW
  • Always includes Db2
  • Deletes QMGR
  • Disables TLS
Published
Read time21 min
AuthorMainframeMaster
Verified: IBM MQ 9.3 documentation