[jboss-user] [JBoss Messaging] - Re: Problems at Startup with MySQL 5 and XAConnection

timfox do-not-reply at jboss.com
Mon Aug 28 17:20:42 EDT 2006


As already mentioned, it's completely pointless using an XADatasource for the messaging database connection, since internally we suspend any current tx and create a new tx for the duration of the database operation.

That tx is not available to have any other resource enlisted in it.

So, you should always use an local-tx datasource.

If you want to send (or acknowledge) message(s) in the same global tx as something else (e.g. updating a database) then you can either:

1) Use the XAResource directly (this is a bit fiddly and I suggest you read the JTA spec first to ensure you know what you are doing)

something like this off the top of my head:


  | 
  | transactionManager.begin();
  | 
  | Transaction tx = transactionManager.getTransaction();
  | 
  | XAConnectionFactory cf = (XAConnectionFactory)ic.lookup("/XAConnectionFactory");
  | 
  | XAConnection connection = cf.createConnection();
  | 
  | XASession sess = connection.createXASession();
  | 
  | XAResource res = sess.getXAResource();
  | 
  | tx.enlistResource(res);
  | 
  | MessageProducer producer = sess.createProducer(queue);
  | 
  | producer.send(sess.createMessage());
  | 
  | XAResource res2 = getXAResourceForYourdatabase();
  | 
  | tx.enlistResource(res2);
  | 
  | //do something with your database
  | 
  | tx.commit();
  | 
  | 

You can find xa examples in the Jboss messaging test suite

org.jboss.test.messaging.jms.XATest

Alternatively, if you are executing in a managed (read, JCA enabled) environment then you can use a UserTransaction, this is a whole lot easier.

Managed environments typically include servlets, and inside ejbs.

To do this, just start a user transaction, send your message and do your database update, commit and that should all happen in the same global tx.

You just need to make sure you are using the jms JCA resource adapter - this is the one normally available at java:/jmsXA, and are using a JCA managed data source for your database access.

See the JCA wiki pages for more information.









View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3967936#3967936

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3967936



More information about the jboss-user mailing list