XAResource res = xaSession.getXAResource();
tm.begin();
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
//This should cause the work done previously to be converted into work done in the xa transaction
//this is what an MDB does
//There is a difficulty in transactional delivery with an MDB.
//The message is received from the destination and then sent to the mdb container so
//it can call onMessage.
//For transactional delivery the receipt of the message should be in a transaction but by the time
//the mdb container is invoked the message has already been received it is too late - the message
//has already been received and passed on (see page 199 (chapter 5 JMS and Transactions, section "Application Server Integration"
//of Mark Little's book Java Transaction processing
//for a discussion of how different app serves deal with this)
//The way jboss messaging (and jboss mq) deals with this is to convert any work done
//prior to when the xasession is enlisted in the tx, into work done in the xa tx
tx.delistResource(res, XAResource.TMSUCCESS);
//Now rollback the tx - this should cause redelivery of the two messages
tx.rollback();
rm1 = (TextMessage)cons.receive(1000);
assertNotNull(rm1);