Question

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).

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top