xa transactions in stand alone processes.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   pete_mckinstry
Posted On:   Thursday, May 27, 2004 02:54 PM

We have some stand alone batch processes that use JOTM to provide xa transactions across data sources. There are some cases where we'd like to send JMS messages as part of these same transactions. Can swift mq participate in such a transaction?


I read through the XA swiftlet documentation, but all the docs seem to be geared towards incorporating it into an app server. Any pointers on it's use outside an app server would be much appreciated.


Thanks.


-pgm

Re: xa transactions in stand alone processes.

Posted By:   Andreas_Mueller  
Posted On:   Friday, May 28, 2004 03:17 AM

Here's an example how to use JMS XA (sends 5 messages to a queue and then receives them):

XAQueueConnectionFactory qcf = null;
XAQueueConnection qc = null;
XAQueueSession qs = null;
QueueSender sender = null;
QueueReceiver receiver = null;
Queue queue = null;
XAResource xares = null;

qcf = (XAQueueConnectionFactory) ctx.lookup(name);
qc = qcf.createXAQueueConnection();
qc.start();
queue = (Queue)ctx.lookup(queueName);
qs = qc.createXAQueueSession();
xares = qs.getXAResource();
sender = qs.getQueueSession().createSender(queue);
receiver = qs.getQueueSession().createReceiver(queue);

Xid xid = new XidImpl();
xares.start(xid, XAResource.TMNOFLAGS);
TextMessage msg = qs.createTextMessage();
for (int i = 0; i < 5; i++)
{
msg.setText("Msg: " + i);
sender.send(msg, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
}
xares.end(xid, XAResource.TMSUCCESS);
xares.prepare(xid);
xares.commit(xid, false);

xid = new XidImpl();
xares.start(xid, XAResource.TMNOFLAGS);
for (int i = 0; i < 5; i++)
{
msg = (TextMessage) receiver.receive(2000);
assertTrue("Received msg==null", msg != null);
}
xares.end(xid, XAResource.TMSUCCESS);
xares.prepare(xid);
xares.commit(xid, false);


Note that the Xid is what you have to provide (in the above example it's our test XidImpl). It must be a separate branch for JMS.
About | Sitemap | Contact