// Step 11. Create two Text Messages
TextMessage helloMessage = session.createTextMessage("hello");
TextMessage worldMessage = session.createTextMessage("world");
// Step 12. create a transaction
Xid xid1 = new DummyXid("xa-example1".getBytes(), 1, UUIDGenerator.getInstance()
.generateStringUUID()
.getBytes());
// Step 13. Get the JMS XAResource
XAResource xaRes = xaSession.getXAResource();
// Step 14. Begin the Transaction work
xaRes.start(xid1, XAResource.TMNOFLAGS);
// Step 15. Send two messages.
normalProducer.send(helloMessage);
normalProducer.send(worldMessage);
// Step 16. Receive the message
TextMessage rm1 = (TextMessage)xaConsumer.receive();
System.out.println("Message received: " + rm1.getText());
TextMessage rm2 = (TextMessage)xaConsumer.receive();
System.out.println("Message received: " + rm2.getText());
// Step 17. Stop the work
xaRes.end(xid1, XAResource.TMSUCCESS);
// Step 18. Prepare
xaRes.prepare(xid1);
// Step 19. Roll back the transaction
xaRes.rollback(xid1);
// Step 20. Create another transaction
Xid xid2 = new DummyXid("xa-example2".getBytes(), 1, UUIDGenerator.getInstance()
.generateStringUUID()
.getBytes());
// Step 21. Start the transaction
xaRes.start(xid2, XAResource.TMNOFLAGS);