broker.start();
String url = "tcp://localhost:61616";
String qName = "MyQueue";
int timeout = 5;
DefaultXidFactory xidFactory = new DefaultXidFactory();
ActiveMQXAConnectionFactory xacf = new ActiveMQXAConnectionFactory();
xacf.setBrokerURL(url);
ActiveMQQueue queue = new ActiveMQQueue();
queue.setPhysicalName(qName);
XAConnection xaconn = xacf.createXAConnection();
xaconn.start();
XASession session = xaconn.createXASession();
XAResource xares = session.getXAResource();
MessageConsumer receiver = session.getSession().createConsumer(queue);
xares.recover(XAResource.TMSTARTRSCAN);
xares.recover(XAResource.TMNOFLAGS);
xares.setTransactionTimeout(timeout);
xares.isSameRM(xares);
Xid xid = xidFactory.createXid("part1", "part2");
xares.start(xid, XAResource.TMNOFLAGS);
receiver.receive(timeout);
xares.end(xid, XAResource.TMSUCCESS);
xares.rollback(xid);