use of javax.jms.XAConnection in project activemq-artemis by apache.
the class SimpleOpenWireTest method testXAPrepare.
@Test
public void testXAPrepare() throws Exception {
try {
XAConnection connection = xaFactory.createXAConnection();
XASession xasession = connection.createXASession();
Xid xid = newXID();
xasession.getXAResource().start(xid, XAResource.TMNOFLAGS);
Queue queue = xasession.createQueue(queueName);
MessageProducer producer = xasession.createProducer(queue);
producer.send(xasession.createTextMessage("hello"));
producer.send(xasession.createTextMessage("hello"));
xasession.getXAResource().end(xid, XAResource.TMSUCCESS);
xasession.getXAResource().prepare(xid);
connection.close();
System.err.println("Done!!!");
} catch (Exception e) {
e.printStackTrace();
}
}
use of javax.jms.XAConnection in project activemq-artemis by apache.
the class SimpleOpenWireTest method testXAConsumer.
@Test
public void testXAConsumer() throws Exception {
Queue queue;
try (Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE)) {
queue = session.createQueue(queueName);
System.out.println("Queue:" + queue);
MessageProducer producer = session.createProducer(queue);
for (int i = 0; i < 10; i++) {
TextMessage msg = session.createTextMessage("test" + i);
msg.setStringProperty("myobj", "test" + i);
producer.send(msg);
}
session.close();
}
try (XAConnection xaconnection = xaFactory.createXAConnection()) {
Xid xid = newXID();
XASession session = xaconnection.createXASession();
session.getXAResource().start(xid, XAResource.TMNOFLAGS);
MessageConsumer consumer = session.createConsumer(queue);
xaconnection.start();
for (int i = 0; i < 5; i++) {
TextMessage message = (TextMessage) consumer.receive(5000);
Assert.assertNotNull(message);
Assert.assertEquals("test" + i, message.getText());
}
session.getXAResource().end(xid, XAResource.TMSUCCESS);
session.getXAResource().rollback(xid);
consumer.close();
xaconnection.close();
}
try (Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) {
connection.start();
MessageConsumer consumer = session.createConsumer(queue);
for (int i = 0; i < 10; i++) {
TextMessage message = (TextMessage) consumer.receive(5000);
Assert.assertNotNull(message);
// Assert.assertEquals("test" + i, message.getText());
System.out.println("Message " + message.getText());
}
checkDuplicate(consumer);
System.out.println("Queue:" + queue);
session.close();
}
System.err.println("Done!!!");
}
use of javax.jms.XAConnection in project activemq-artemis by apache.
the class SimpleOpenWireTest method testXAResourceRolledBackRemoved.
@Test
public void testXAResourceRolledBackRemoved() throws Exception {
Queue queue = null;
Xid xid = newXID();
try (XAConnection xaconnection = xaFactory.createXAConnection()) {
XASession session = xaconnection.createXASession();
queue = session.createQueue(queueName);
session.getXAResource().start(xid, XAResource.TMNOFLAGS);
MessageProducer producer = session.createProducer(queue);
producer.send(session.createTextMessage("xa message"));
session.getXAResource().end(xid, XAResource.TMSUCCESS);
session.getXAResource().rollback(xid);
}
XidImpl xid1 = new XidImpl(xid);
Transaction transaction = server.getResourceManager().getTransaction(xid1);
assertNull(transaction);
}
use of javax.jms.XAConnection in project activemq-artemis by apache.
the class ConnectionTest method testXAInstanceof.
@Test
public void testXAInstanceof() throws Exception {
conn = cf.createConnection();
assertFalse(conn instanceof XAConnection);
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertFalse(sess instanceof XASession);
}
use of javax.jms.XAConnection in project narayana by jbosstm.
the class ProtocolConverter method getXASession.
protected StompSession getXASession(Xid xid) throws JMSException {
StompSession xaSession = xaSessions.get(xid);
if (xaSession == null) {
XAConnection xaConnection;
if (login != null) {
xaConnection = xaConnectionFactory.createXAConnection(login, passcode);
} else {
xaConnection = xaConnectionFactory.createXAConnection();
}
if (clientId != null) {
xaConnection.setClientID(clientId);
}
xaConnection.start();
Session session = xaConnection.createXASession();
if (log.isDebugEnabled()) {
log.debug("Created XA session");
}
xaSession = new StompSession(initialContext, this, session, xaConnection);
log.trace("Created XA Session");
xaSessions.put(xid, xaSession);
} else {
log.trace("Returned existing XA session");
}
return xaSession;
}
Aggregations