Writing and modifying the applications
How to implement a global unit of work.
The sample application programs for Scenario 1 global units of work that are supplied with an IBM MQ installation are described in the Introducing units of work.
In general, a global unit of work is implemented in an application by the following method (in pseudocode):The purpose of MQBEGIN is to denote the beginning of a global unit of work. The purpose of MQCMIT is to denote the end of the global unit of work, and to complete it with all participating resource managers, using the two-phase commit protocol.
In between MQBEGIN and MQCMIT, the queue manager does not make any calls to the database to update its resources. That is, the only way a database's tables are changed is by your code (for example, the SQL INSERT in the pseudocode).
The role of the queue manager, as far as the database is concerned, is to tell it when a global unit of work has started, when it has ended, and whether the global unit of work should be committed or rolled-back.
As far as the application is concerned, the queue manager performs two roles: a resource manager (where the resources are messages on queues) and the transaction manager for the global unit of work.
Start with the supplied sample programs, and work through the various IBM MQ and database API calls that are being made in those programs. The API calls concerned are fully documented in Sample IBM MQ procedural programs, Data types used in the MQI, and (in the case of the database's own API) the database's own documentation.
Parent topic: Configure the system for database coordination