vjm
vjm

Reputation: 59

Should JmsTransactionManager be used when persisting from one JMS Queue to another JMS Queue

Requirement: We need to retrieve a message from a JMS Queue(published by a different application) and persist the message in our JMS Queue. Need the entire flow to be transactional so in case a message cannot be persisted in the downstream JMS queue, message received from upstream JMS Queue should not be acknowledged. My configuration is as below

<int-jms:message-driven-channel-adapter
   id="MessageDrivenAdapter" channel=" jmsMessageChannel " destination="sourceDestination" 
     connectionFactory="CF1"
acknowledge="transacted"
    />

<int:channel id=" jmsMessageChannel " />
<int-jms:outbound-channel-adapter id="sendsomemsg"
    channel=" jmsMessageChannel "  destination=”finalDestination”
    connectionFactory="CF2"
    session-transacted="true" />

Do I need to use JmsTransactionManager in this scenario or should be above configuration suffice. We can handle duplicate messages so I believe we do not need an XA transaction.

Upvotes: 0

Views: 326

Answers (2)

Gary Russell
Gary Russell

Reputation: 174554

As long as you don't hand off to another thread (queue channel, task executor), and both components are using the same connection factory, the outbound operation will run in the same transaction as the inbound - the underlying JmsTemplatein the outbound adapter will use the same session that the listener container delivered the message on.

Upvotes: 0

Artem Bilan
Artem Bilan

Reputation: 121262

You definitely need XA transaction here because you are using several separate transactional resources. Even if they both are JMS, that doesn't mean that they can share transaction.

OTOH you can try a solution like ChainedTransactionManager and chain two JmsTransactionManagers - one for each your JMS resource.

More info is in Dave Syer's article.

Upvotes: 2

Related Questions