activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eugene Prokopiev <prokop...@stc.donpac.ru>
Subject Re: XA in standalone JMS client
Date Mon, 21 Aug 2006 08:30:25 GMT
> You need to enlist resources with JTA. I'd suggest reading the JTA
> javadoc and specification.
> 
> http://java.sun.com/j2ee/1.4/docs/api/javax/transaction/Transaction.html

Thanks. This code works as I need:

public class AMQXATest {

	public static void main(String[] args) throws Exception {
		
		// start broker 		
		BrokerService broker = new BrokerService();
		broker.setPersistent(false);
		broker.addConnector("tcp://localhost:5000");
		broker.start();
		
		// start transaction manager
		TMService jotm = new Jotm(true, false);
		UserTransaction transaction = jotm.getUserTransaction();
		TransactionManager transactionManager = jotm.getTransactionManager();
		
		// start connection
		ActiveMQXAConnectionFactory connectionFactory =
			new ActiveMQXAConnectionFactory("tcp://localhost:5000");
		XAConnection connection = connectionFactory.createXAConnection();
		XASession session = connection.createXASession();
		Destination destination = session.createQueue("messages.input");
         MessageProducer producer = session.createProducer(destination);

         // send message
         TextMessage message = session.createTextMessage("Test Message 
String");
         transaction.begin();
 
transactionManager.getTransaction().enlistResource(session.getXAResource());
         System.out.println(transactionManager.getTransaction());
         producer.send(message);
         transaction.commit();
         System.out.println("sent message : "+message.getJMSMessageID());

         // close connection
         session.close();
         connection.close();		
	}

}

Main disadvantage is using UserTransaction and TransactionManager while 
sending message because I can't start transaction with 
TransactionManager and can't enlist XASession with UserTransaction.

How can I refactor this code to use only UserTransaction or 
TransactionManager while sending message?

--
Thanks,
Eugene Prokopiev


Mime
View raw message