2 Replies Latest reply: Jul 4, 2011 2:24 PM by 452196 RSS

    Some advice on Spring transactions please

    452196
      I have a pretty straightforward program that uses the Spring annotation driven transaction thing to manage JMS contexts. I'm currently trying to port it from openMq to activeMQ in the hope of getting a more resilient system. The one we have tends to fall over every few weeks, typically triggered by a database connection problem crashing a broker.

      Briefly the program I'm having the most trouble with polls a web service for blocks of data records and republishes them through JMS for local consumption.

      I'm somewhat confused about the way the transaction system is handled, and what ConnectionFactory to use. The ActiveMQ documentation recommends using a wrapper of some sort, like CachedConnectionFactory (to avoid constant connect and disconnect) but this seems to trigger problems, in particular a "Transaction was not started" exception on commit.

      It's complicated by the fact that I'm using a JMS logging system, which uses the same ConnectionFactory to publish log records on another destination, which may occur inside or outside of the standard transaction. Clearly these logging publications shouldn't be rolled back as part of the main transaction.

      1) What do I need to do in my logging handler to force the log records to be published immediately, whether or not a transaction is in progress.

      2) What connection factory wrappers are OK with transactions.

      3) Should the connection factory reference in the JmsTransactionManager be to the underlying factory, or the wrapper.

      4) Do I needs to tell the JmsTemplate that transactions are in use.

      5) How do I combine JMS and JPA transactions where necessary.
        • 1. Re: Some advice on Spring transactions please
          r035198x
          malcolmmc wrote:
          I have a pretty straightforward program that uses the Spring annotation driven transaction thing to manage JMS contexts. I'm currently trying to port it from openMq to activeMQ in the hope of getting a more resilient system. The one we have tends to fall over every few weeks, typically triggered by a database connection problem crashing a broker.

          Briefly the program I'm having the most trouble with polls a web service for blocks of data records and republishes them through JMS for local consumption.

          I'm somewhat confused about the way the transaction system is handled, and what ConnectionFactory to use. The ActiveMQ documentation recommends using a wrapper of some sort, like CachedConnectionFactory (to avoid constant connect and disconnect) but this seems to trigger problems, in particular a "Transaction was not started" exception on commit.

          It's complicated by the fact that I'm using a JMS logging system, which uses the same ConnectionFactory to publish log records on another destination, which may occur inside or outside of the standard transaction. Clearly these logging publications shouldn't be rolled back as part of the main transaction.

          1) What do I need to do in my logging handler to force the log records to be published immediately, whether or not a transaction is in progress.

          2) What connection factory wrappers are OK with transactions.

          3) Should the connection factory reference in the JmsTransactionManager be to the underlying factory, or the wrapper.

          4) Do I needs to tell the JmsTemplate that transactions are in use.
          You should ask spring questions in a spring specific forum.
          5) How do I combine JMS and JPA transactions where necessary.
          You'll need to configure a driver that supports XA transactions for the JPA datasource and use a JTA compilant transaction manager.

          Edited by: r035198x on 03-Jul-2011 09:36
          • 2. Re: Some advice on Spring transactions please
            452196
            I think I've sorted out the logging thing anyway. I gave the logger a thread of it's own to do the JMS sends on, feeding the log records to it through a BlockingQueue.

            Transactions are thread specific.