Consuming Messages in XA Transactions

To consume messages in XA transaction branches, a client must create a message consumer in the XA Session for the persistent and non‑persistent messages to be received.

To create a message consumer in an XA Session, call the XASession.createConsumer(...) method and pass in a queue or topic destination. For more information on creating message consumers and their operation, refer to Creating Message Consumers.

When a message consumer in an XA Session is bound to a queue (either exclusive or non‑exclusive), message consumers in non-XA Sessions are not permitted to subsequently bind to that queue. In addition, if a message consumer in a non-XA Session is bound to a non‑exclusive queue, message consumers in XA Sessions cannot subsequently bind to that queue. These restrictions prevent delivering out‑of‑order messages to consumers in non-XA Sessions if a transaction rollbacks are performed.

Messages received in an XA Session are only assigned to a transaction branch after XAResource.end(...) is called (refer to Ending Transactions). A maximum of 256 messages (combined publisher and/or subscriber messages) can be assigned to a transaction branch. If this limit is exceeded, a rollback occurs and an XAException is thrown.

Unlike messages received in a non-transacted Session, messages received in an XA Session are only acknowledged, and subsequently removed from the event broker, when a successful XAResource.commit(...) occurs for the transaction branch. Therefore, calling Message.acknowledge() has no effect on a transaction branch.

A message consumer created within a XA Session can only consume messages when a transaction branch in that XA Session is committed, and it cannot consume messages outside of that XA Session.

If messages in a transaction branch that are to be consumed are removed from the message spool for the following reasons after an XA Prepare call but before an XA Commit, they are still successfully committed:

  • The messages are removed from the event broker by an XA Prepare action (that is, the messages are deleted from the spool).
  • The messages’ TTL has expired. Note that the commit succeeds whether or not expired messages are moved to a Dead Message Queue (DMQ). For information on DMQs, refer to Dead Message Queue Eligibility.