Hi,
I'm currently using OpenMQ in my app and I need to support distributed transactions.
I'm trying to understand what I need to change in the configuration (and where) and how will switching to a JTA change the way I'm currently obtaining my ConnectionFactory
and handling my javax.jms.Connection
.
A quick code example of my usage is (assume MyQSender holds a member type of Message):
myQSender = new MyQSender(); myQSender.InitQ(MY_QUEUE_NAME); ... myQSender.Create(myObj); myQSender.SetProperty("property","value"); myQSender.SendMessage();
And these are the back-stage classes:
public class QSender { private MessageProducer myProducer; private String myName; private QFactory factory; protected boolean Init(String name){ myName = name; try{ factory = new QFactory(); myProducer = factory.CreateProducer(name); } catch (Exception e) { log.Error("QSender exception", e); } return true; } public boolean Close(){ factory.Close(); return true; } protected Message CreateMessage(Object obj){ try{ ObjectMessage outMsg = factory.GetSession().createObjectMessage(); outMsg.setObject((Serializable) obj); return outMsg; } catch (javax.jms.JMSException e) { log.Error("QSender exception", e); return null; } } protected boolean SendMessage(ObjectMessage outMsg){ try{ myProducer.send(outMsg); } catch (javax.jms.JMSException e) { log.Error("QSender exception", e); return false; } return true; } public class QFactory { private Logger log ; Connection myConnection; Session mySession ; public Session GetSession(){ return mySession; } public Connection GetConnection(){ return myConnection; } public MessageProducer CreateProducer(String name) throws Exception{ javax.jms.Destination myDest = Create(name); MessageProducer myProducer = mySession.createProducer(myDest); return myProducer; } public MessageConsumer CreateReceiver(String name) throws Exception{ javax.jms.Destination myDest = Create(name); MessageConsumer myConsumer= mySession.createConsumer(myDest); return myConsumer; } private Destination Create(String name)throws Exception{ try{ String AddressList = "localhost:7676"; ConnectionFactory myFactory = new com.sun.messaging.ConnectionFactory(); myFactory.setProperty(ConnectionConfiguration.imqAddressList,AddressList); myConnection = myFactory.createConnection(); myConnection.setExceptionListener(new QExceptionListener(this,name,false)); mySession = myConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination myDest = new com.sun.messaging.Queue(name); return myDest; } catch (JMSException e){ // Q connection error wait interval and try again log.Error(e.getMessage()); Thread.sleep(5000); return Create(name, isProducer); } } public boolean Close(){ try{ mySession.close(); myConnection.close(); } catch (javax.jms.JMSException e) { log.Error("QFactory exception", e); return false; } return true; } public void commit() throws JMSException { mySession.commit(); } public void rollback() throws JMSException { mySession.rollback(); } }
I'd appreciate all the help I can get,
Ittai