Publishing Messages in XA Transactions
To publish messages in a transaction branch to a queue or topic destination, a MessageProducer
must be created in the XA Session to establish a producer flow.
To create a message producer, call XASession.createProducer(Destination destination)
in the obtained XA Session.
To then publish messages in the XA Session, call MessageProducer.send(...)
.
When messages are published in an XA Session after XAResource.start(...)
is called, the event broker stages the published messages and assigns them to the transaction branch. However, the messages are not delivered to their destinations on the event broker until XAResource.commit(...)
is called. A successful commit will deliver the messages to their destinations and remove the staging information.
When messages are published in an XA Session before XAResource.start(...)
is called, they are handled in same way as messages that are published in a regular Session. That is, they are not "transacted" messages.
How Endpoint Message Discards Affect XA Transactions
When a message that was published in a transaction branch cannot be spooled successfully to any of its destination endpoints on a commit, the message is discarded. In this case, the endpoint's reject-msg-to-sender-on-discard
property determines whether the commit is successful.
The message discard behavior for a regular Session-based transaction and an XA Session-based transaction are the same. For more information, refer to How the Behavior of Endpoint Message Discard Affects Transactions.