Recovering transactions in IBM MQ .NET
This section describes the process of recovering transactions in IBM MQ .NET XA using managed mode.
Overview
In distributed transaction processing, the transactions can be successfully completed. But, there can be scenarios where a transaction may fail for many reasons. These reasons could include a system failure, hardware failure, network error, incorrect or invalid data, application errors or natural or man-made disasters. It is not possible to prevent transaction failures. The distributed transaction system must be capable of handling these failures. It must be able to detect and correct errors when they occur. This process is known as Transaction Recovery.
An important aspect of the Distributed Transaction Processing is to recover the incomplete or in doubt transactions. It is essential to run the recovery as the Unit of Work part of a particular transaction is held locked until it is recovered. Microsoft.NET from its System.Transactions class library provides the option for recovering incomplete/in-doubt transactions. This recovery support expects Resource Manager to maintain the transaction logs and run the recovery when in need.
Recovery Model
In the Microsoft .NET transaction recovery model, the Transaction Manager (System.Transactions, or Microsoft Distributed Transaction coordinator (MS DTC), or both), initiates, coordinates, and controls the transaction recovery. The OLE Tx Protocol (the Microsoft XA protocol) based Resource Managers provide the options to configure the DTC to drive, coordinate, and control the recovery for them. To do this, Resource Managers must register XA_Switch with MS DTC by using native interface.
XA_Switch provides the entry points of XA functions like xa_start, xa_end, and xa_recover in the Resource Manager to the Distributed Transaction Coordinator.
- Recovery using Microsoft Distributed Transaction coordinator (DTC):
Microsoft Distributed Transaction coordinator provides two kinds of recovery processes.
- Cold Recovery
Cold recovery is performed if the transaction manager process fails while a connection to a XA resource manager is open. When the transaction manager restarts, it reads the transaction manager logs and re-establishes the connection to the XA resource manager and then initiates recovery.
- Hot Recovery
Hot recovery is performed if the transaction manager remains up while the connection between the transaction manager and the XA resource manager fails because the XA resource manager or the network fails. After the failure, the transaction manager periodically attempts to reconnect to the XA resource manager. When the connection is re-established, the transaction manager initiates XA recovery.
System.Transactions namespace provides managed implementation of Distributed transactions that are based on MS DTC as the transaction manager. It provides similar features as that of MS DTC's native interface but in fully managed environment. The only difference is about the transaction recovery. System.Transactions expects Resource Managers to drive the recovery by themselves and then coordinate with the Transaction Managers (MS DTC). Resource Manager must ask for recovery of a particular incomplete transaction and then Transaction Manager accepts it and coordinates based on the actual outcome of that particular transaction.
- IBM MQ .NET Distributed Transaction Processing - Recovering Transaction
This section describes how transactions can be recovered with IBM MQ .NET classes.- Use WMQDotnetXAMonitor application
The WMQDotnetXAMonitor application must be run manually. It can be started at any time. We can start it when you see the messages on the SYSTEM.DOTNET.XARECOVERY.QUEUE or we can keep it running in the background before you do any transactional work with the applications that are written using IBM MQ .NET classes.- WmqDotNETXAMonitor Configuration Settings
To monitor the application, inputs can also be provided using the application configuration file. A sample application configuration file is shipped with IBM MQ .NET. This file can be modified according we requirements.- WmqDotNetXAMonitor Application log
Monitor Application creates a log file in the application directory for logging the Monitor's progress and transaction recovery status. Logging starts with the connection name and the channel details to show current queue manager for which the recovery is running.- Recovering transactions: Use cases
There are several different use cases from which transactions might need to be recovered.Parent topic: Distributed transactions in .NET