All transactions initiated by client applications are tracked by the broker. These can be simple Message Queue transactions or distributed transactions managed by a distributed transaction (XA resource) manager.
Each transaction has a Message Queue transaction ID:a 64 bit number that uniquely identifies a transaction on the broker. Distributed transactions also have a distributed transaction ID (XID), up to 128 bytes long, assigned by the distributed transaction manager. Message Queue maintains the association of an Message Queue transaction ID with an XID.
For distributed transactions, in cases of failure, it is possible that transactions could be left in a PREPARED state without ever being committed. Hence, as an administrator you might need to monitor and then roll back or commit transactions left in a prepared state.
To list all transactions, being tracked by the broker, use the list txn command. This is the syntax for the list tx subcommand:
imqcmd list txn
For example, the following command lists all transactions in a broker.
imqcmd list txn
For each transaction, the list subcommand returns the transaction ID, state, user name, number of messages or acknowledgments, and creation time. For example:
--------------------------------------------------------------- Transaction ID State User name # Msgs/ Creation time # Acks --------------------------------------------------------------- 64248349708800 PREPARED guest 4/0 1/30/02 10:08:31 AM 64248371287808 PREPARED guest 0/4 1/30/02 10:09:55 AM |
The command shows all transactions in the broker, both local and distributed. You can only commit or roll back transactions in the PREPARED state. You should only do so if you know that the transaction has been left in this state by a failure and is not in the process of being committed by the distributed transaction manager.
For example, if the broker’s auto-rollback property is set to false (see Table 14–2), you must manually commit or roll back transactions found in a PREPARED state at broker startup.
The list subcommand also shows the number of messages that were produced in the transaction and the number of messages that were acknowledged in the transaction (#Msgs/#Acks). These messages will not be delivered and the acknowledgments will not be processed until the transaction is committed.
The query subcommand lets you see the same information plus a number of additional values: the Client ID, connection identification, and distributed transaction ID (XID). This is the syntax of the query txn subcommand:
imqcmd query txn -n transactionID
For example, the following example produces the output shown below:
imqcmd query txn -n 64248349708800
Client ID Connection guest@192.18.116.219:62209->jms:62195 Creation time 1/30/02 10:08:31 AM Number of acknowledgments 0 Number of messages 4 State PREPARED Transaction ID 64248349708800 User name guest XID 6469706F6C7369646577696E6465723130313234313431313030373230 |
Use the commit and rollback subcommands to commit or roll back a distributed transaction. As mentioned previously, only a transaction in the PREPARED state can be committed or rolled back.
This is the syntax of the commit subcommand:
imqcmd commit txn -n transactionID
For example:
imqcmd commit txn -n 64248349708800
This is the syntax of the rollback. subcommand:
imqcmd rollback txn -n transactionID
See the imq.transaction.autorollback property in Table 14–2 for more information.
It is also possible to configure the broker to automatically roll back transactions in the PREPARED state at broker startup.