activemq-artemis/examples/features/standard/xa-send
Clebert Suconic 3dea7eeb71 [maven-release-plugin] prepare release 2.20.0 2021-12-14 22:50:53 -05:00
..
src/main ARTEMIS-3538 fix extra-tests formatting and examples compilation 2021-11-03 14:57:58 +01:00
pom.xml [maven-release-plugin] prepare release 2.20.0 2021-12-14 22:50:53 -05:00
readme.md ARTEMIS-1562 Refactor example documentation 2017-12-15 14:54:16 +00:00

readme.md

JMS XA Send Example

To run the example, simply type mvn verify from this directory, or mvn -PnoServer verify if you want to start and create the broker manually.

This example shows you how message sending behaves in an XA transaction in ActiveMQ Artemis. When a message is sent within the scope of an XA transaction, it will only reach the queue once the transaction is committed. If the transaction is rolled back the sent messages will be discarded by the server.

ActiveMQ Artemis is JTA aware, meaning you can use ActiveMQ Artemis in a XA transactional environment and participate in XA transactions. It provides the javax.transaction.xa.XAResource interface for that purpose. Users can get a XAConnectionFactory to create XAConnections and XASessions.

In this example we simulate a transaction manager to control the transactions. First we create an XASession and enlist it in a transaction through its XAResource. We then send two words, hello and world, with the session, let the transaction roll back. The messages are discarded and never be received. Next we start a new transaction with the same XAResource, but this time we commit the transaction. Both messages are received.