I have problems with user transactions in servlets. I want to make some database entries and send a JMS message as an atomic piece of work, protected by a user transaction. While the database resource is committing and rollbacking correctly, the JMS message is not committed by the transaction manager. Is JBoss 3.0.4/Jetty ready for doing something like this or what am I doing wrong. Unfortunately using a session facade is not an option because I have to process SOAP messages with attachments in the transaction.
Here are fragments of the code:
try {
ut = (UserTransaction)initContext.lookup("java:comp/UserTransaction");
qcf = (QueueConnectionFactory)initContext.lookup("java:comp/env/jms/QueueConnectionFactory");
// using XAConnectionFactory
conn = qcf.createQueueConnection();
conn.start();
session = conn.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
jobReceiverQueue = (Queue)initContext.lookup("java:comp/env/jms/queue/jobreceiver");
sender = session.createSender(jobReceiverQueue);
ut.begin();
// doing some databases updates
// creating a jms message
sender.send(jmsmsg);
ut.commit();
} catch (Exception ex) {
ut.rollback();
// ...
} finally {
sender.close();
session.close();
conn.stop();
conn.close();
}
Thanks,
Manfred
Are you using the connection factory bound at
java:/JmsXA
This is the only connection factory that knows
about the ejb transactions.
The others use the JMS client notion of a transaction.
Regards,
Adrian