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

淺唱寂寞╮ 提交于 2019-12-12 05:07:04

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/42441359/should-jmstransactionmanager-be-used-when-persisting-from-one-jms-queue-to-anoth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!