13 Replies Latest reply: Feb 7, 2011 4:57 AM by Leos Bitto RSS

How does one set the TransactionManager on a HornetQ server ?

Miroslav Pokorny Newbie

I am trying to set the tx manager on a standalone instance outside of a j2ee container however i cannot find a setTransactionManager or equivalent method. If it matters i am also using the JMS layer.

  • 1. How does one set the TransactionManager on a HornetQ server ?
    Miroslav Pokorny Newbie

    I forgot to include this enhancement request which remains incomplete

     

    https://issues.jboss.org/browse/HORNETQ-417

  • 2. How does one set the TransactionManager on a HornetQ server ?
    Andy Taylor Master

    what your asking doesn't really make sense. What is it you are trying to acheive?

  • 3. How does one set the TransactionManager on a HornetQ server ?
    Miroslav Pokorny Newbie

    Sorry i will clairfy.

     

    I am using HornetQ as an embedded messaging system, using core and the jms layer. However I am not using JNDI and would like to know how to "set" or perhaps provide a "locator" to supply a TransactionManager to the HornetQ system.

     

    I have scanned the source and could not find any method that sets for either javax.transaction.Transaction | TransactionManager or org.hornetq.core.transaction.Transaction. The only place i could find that accepts a TM (pretty sure it was a TM ) was the JMSBridge class which i dont need.

  • 4. How does one set the TransactionManager on a HornetQ server ?
    Andy Taylor Master

    My original comment still stands, let me explain the relationship between HrnetQ and a tm. Apart from the JMS Bridge HornetQ does not use or need a transaction manager. A Transaction Manager is used to orchestrate distributed transactions usuall within Application Servers with MDB's etc., HornetQ Sessions provide XA support and a tm will enlist these xa sessions and call rollback/commit etc, again if you tell me what you are trying to acheive maybe i can help more.

  • 5. Re: How does one set the TransactionManager on a HornetQ server ?
    Miroslav Pokorny Newbie

    I am trying to get HornetQ sessions and the messages that get sent thru them to participate in XA Sessions. However stepping back without providing a TM i cant figure out how HornetQ will find be able to do all the steps to find out about all the events during the stages of a 2phase tx. I want would like rollbacks or commits to also cancel messages that are sent/published so that as many things as possible fail or succeed together. I am not using JNDI so i would therefore like to supply the TM as an instance to the HornetQ system.

     

    You mentioned in your last post that HornetQ does need a TM but how does one commit/rollback sent/taken messages as part of a unit of work ?

  • 6. How does one set the TransactionManager on a HornetQ server ?
    Andy Taylor Master

    firstly JNDi has nothing to do with using a transaction manager, secondly like i mentioned before HornetQ doesnt use a transaction manager, its the other way around, its a transaction manager that would use a HornetQ XASession.

     

    maybe you are misunderstanding the relationship between a transaction manager and a solution that provides XA support in the form of an XAResource. Take a look at one of the XA examples it may become clearer.

  • 7. How does one set the TransactionManager on a HornetQ server ?
    Miroslav Pokorny Newbie

    Thanks for the pointer i will look at the sample again.

     

    My undestanding was that behind the scenes, the XAResource in this case soemthing inside HornetQ would need a TM so it can "add" itself so it receives notifications about prepares, commits rollbacks and all the callbacks in XAResource.

  • 8. How does one set the TransactionManager on a HornetQ server ?
    Andy Taylor Master
    My undestanding was that behind the scenes, the XAResource in this case soemthing inside HornetQ would need a TM so it can "add" itself so it receives notifications about prepares, commits rollbacks and all the callbacks in XAResource.

    No, its the other way around. something like

     

    tm.getTransaction().enlistResource(xaSession.getXAResource().

     

    This is typically only done by Application Servers, are you sure you need a transaction manager or XA at all. If a single instance of HornetQ is used then you don't as you don't actually need 2 phase commit.

     

    maybe if you explained your scenario then i could help more.

  • 9. How does one set the TransactionManager on a HornetQ server ?
    Miroslav Pokorny Newbie

    2PC = im guessing it maybe cant tell for sure now, but it seems sensible to want all or nothing, as in dont update the message queue if the db fails and vice versa.

     

    Your one liner is exactly what im talking about, what i was trying to answer. There must be some mechanism for Hornetq to say hey heres a xasession grab its XAResource after a new tx is started. One of the two has to grab the or receive the xaresource so everything works.

  • 10. How does one set the TransactionManager on a HornetQ server ?
    Andy Taylor Master

    you keep assuming that this is something HornetQ does, think the other way around, if you want to enlist the XA session with a transaction then its your client code that does it, this is outside the remit of HornetQ. Feel free to join us on our irc channel and i can explain in more detail

  • 11. Re: How does one set the TransactionManager on a HornetQ server ?
    Miroslav Pokorny Newbie

    Ill hang around freenode #jboss and #hornetQ and try my luck.

     

    I have been looking at the examples called XASendExample and XAReceiveExample and yes they do include code to call the right XAResources at the right time. This however seems plain wrong, i have never seen typical user code for Hibernate doing the same for tx management. At the very least I would expect the capability to simply start a tx via UserTransaction.begin() and eventually UserTransaction.commit() or rollback(). Behind the scenes all the XAResource callbacks should be handled by the tm, otherwise my code is effect acting like a mini tm by telling.

     

    Sorry i seem thick, this just sounds really wrong imho, i would have thought HornetQ had a XA resource manager of some sort to help me avoid the need to do coordinate all these XAResource callbacks.

  • 12. Re: How does one set the TransactionManager on a HornetQ server ?
    Andy Taylor Master

    What do you think is wrong, like ive explained before we behave like any other xa resource and interact with the transaction manager in the same way, we provide an xa resource that can be enlisted with the transaction manager who will control it.

     

    Remember, this example is just demonstrating how the interaction will work with the tm and how we expose XA resources. In reality, say within an MDB in an Application Server, It would be the AS itself that would use the TM to rollback/commit etc.

     

    Again, if you could explain what you are trying to acheive i could help or joing #hornetq and message me.

  • 13. How does one set the TransactionManager on a HornetQ server ?
    Leos Bitto Novice

    Miroslav, it would work the way you describe inside j2ee container. The container would provide you an implementation of javax.jms.QueueConnectionFactory (using the JTA adapter of the JMS provider), which you could use to access JMS transactionally. Then you have to choose whether the container would manage transactions for you (called "container managed transactions" - basically commit after your method ends, or rollback if your method throws an exception), or if you would like to manage transactions (begin/commit/rollback) yourself (called "bean managed transactions"). In the later case the container would provide you an implementation of javax.transaction.UserTransaction. In both cases it is the container which does the integration of all the transactional resources (think JMS or JDBC or any other resource which is handled by a proper JTA adapter) with the transaction manager. The key method is javax.transaction.Transaction#enlistResource(javax.transaction.xa.XAResource). If you choose to use the j2ee container, there are many tutorials available. If you choose not to use the j2ee container, but still you would like to use the j2ee interfaces from JTA and JMS, your only possibility is to write the necessarry parts of the j2ee container yourself.