1

I have a standalone application (a simple command-line jar) which can already read or produce messages from/to an ActiveMQ queues (no Transaction).

I'd like to add the functionality to be able to read messages from a remote ActiveMQ queue and put it in another remote ActiveMQ queue. The 2 ActiveMQs may be completely different and not the same and I would also like to make sure no messages are lost during transfer should there be any connection issues.

I have been doing quite a lot of reading on transactions and as far as I understand, because I am transfering between 2 completely different ActiveMQs, a simple Spring JmsTransactionManager will not suffice but rather some sort of Distributed Transaction Management is needed (Like XA Transactions).

I am completely lost on the sea of code examples found on the internet regarding several different libraries and such.

Can anybody point me the way to find the simplest solution to this problem? Should I use JTA on top of Spring somehow (Is it even feasible to use JTA on a non-j2ee application server environment)? I am already using spring's jmstemplate to send/receive messages so would be great if I could keep using spring (and preferably no xml context config as I do everything programatically today).

Alexandre Thenorio
  • 2,288
  • 3
  • 31
  • 50

1 Answers1

1

If you do not need the write to the 2nd remote ActiveMQ to be in the same transaction scope as the read, then you can do this without distributed transactions. You can hold open the read transaction until you successfully write to the 2nd remote ActiveMQ. Once that has succeeded, then you can commit the read transaction. This means however, that in the event of failure after the send, but before the read commit, you will end up re-sending the message. Thus, this assumes that duplicate sends are okay. If you cannot tolerate duplicate sends in the event of failure, you must have distributed transactions.

Martin Serrano
  • 3,727
  • 1
  • 35
  • 48
  • Thank you. I had the same thought but hadn't realized the scenario of the duplication. To be honest I'd like to avoid duplicates if possible and performance is not really a problem at the moment so I am thinking of going ahead with Distributed Transactions. I take it in such a scenario I'd be better off with some 3PP JTA implementation such as Atomikos, is that correct? Also in the scenario of simply moving message between 2 queue in the same remote ActiveMQ, would spring's JmsTransactionManager suffice or is that only for embedded instances? – Alexandre Thenorio Feb 22 '14 at 11:43
  • For more details on implementation of distributed (XA) transactions of the above look here http://stackoverflow.com/questions/22072100/xa-transactions-between-2-jms-brokers-activemq – Alexandre Thenorio Mar 03 '14 at 21:38