Websphere MQ transactions

Websphere MQ can send and receive messages as part of a transaction or outside a transaction. If a message is sent or received as part of a transaction, the transaction can include other resource such as DB2® operations.

Websphere MQ can serve as the transaction manager itself or participate as a resource manager to other transaction managers (such as CICS®, Encina, and Tuxedo). Detailed information on transactions and supported external transaction managers can be found in the Websphere MQSeries® Information Center.

Websphere can also participate in transactions managed by IBM® i commitment control. Commitment control is automatically started by DB2 when an SQL statement is executed and it is determined that commitment control is not yet started. By default, the commitment definition scope is *ACTGRP. In order for MQ functions and DB2 operations that occur in the same job to participate in the same transaction managed by IBM i commitment control, commitment control must be started with a scope of *JOB. For example, the following two CL commands end the current commitment definition and starts one with a scope of *JOB:
 ENDCMTCTL
 STRCMTCTL LCKLVL(*CHG) CMTSCOPE(*JOB)
 
In order to start commitment control with a scope of *JOB in a server job, the end and start commitment control CL commands must be performed together in a procedure. The following steps will create a sample procedure called START_JOB_LEVEL_COMMIT which can then be called with an SQL CALL statement :
  1. Enter the following source in a source file member JOBSCOPE in MJASRC/CL:
     PGM
     ENDCMTCTL
     STRCMTCTL LCKLVL(*CHG) CMTSCOPE(*JOB)
     ENDPGM
     
  2. Create the CL program using the following default MQ message queue manager:
     CRTCLPGM PGM(MJATST/JOBSCOPE) SRCFILE(MJASRC/CL)
     
  3. Create the SQL external procedure that references the CL program:
     CREATE PROCEDURE MJATST.START_JOB_LEVEL_COMMIT ()
       EXTERNAL NAME 'MJATST/JOBSCOPE'
       PARAMETER STYLE GENERAL
     
The procedure can typically be called once in a job. Once the commitment definition with a *JOB scope is started, MQ operations and DB2 operations can be performed as part of a transaction. For example, the following INSERT statement and the MQSEND function will be performed under the same transaction. If the transaction is committed, both operations are committed. If the transaction is rolled back, both operations are rolled back.
 CALL MJATST.START_JOB_LEVEL_COMMIT;
 INSERT INTO MJATST.T1
   VALUES(1);
 VALUES MQSEND('A commit test message');
 COMMMIT;

 INSERT INTO MJATST.T1
   VALUES(2);
 VALUES MQSEND('A rollback test message');
 ROLLBACK;
 

Websphere MQ can send and receive messages as part of a transaction or outside a transaction. In a DB2 MQ function this is controlled by the specified policy. Each policy has a SYNCPOINT attribute. If the SYNCPOINT column for a policy has a value of 'N', any DB2 MQ function that uses that policy will not participate in a transaction. If the SYNCPOINT column for a policy has a value of 'Y', any DB2 MQ function that uses that policy and changes the input queue will participate in a transaction.