Transaction handling while using message driven channel adapter & service activator

大城市里の小女人 提交于 2020-01-02 16:30:09

问题


I am working on a POC which does the following

  1. Uses a message driven channel adapter to recieve message in a transaction
  2. Calls the Service Activator which uses a handler to insert the message recieved from the adapter to DB and also post message to outbound channel.

Now, if the DB insert of the message fails i want the JMS message returned back to the queue so that it can be re-tried later.

With my below configuration it doesnt seems to work.(i.e. even if there is a failure while inserting into the database the message is removed from the queue.

Any pointers or sample configuration would be helpful.

<integration:channel id="jmsInChannel">         
    <integration:queue/>
</integration:channel>

<int-jms:message-driven-channel-adapter id="jmsIn"
    transaction-manager="transactionManager"
    connection-factory="sConnectionFactory"
    destination-name="emsQueue"
    acknowledge="client" channel="jmsInChannel"
    extract-payload="false"/>   

<integration:service-activator input-channel="jmsInChannel"
    output-channel="fileNamesChannel" ref="handler" method="process" />

<bean id="handler" class="com.irebalpoc.integration.MessageProcessor">
    <property name="jobHashTable" ref="jobsMapping" />
</bean>

回答1:


Set acknowledge="transacted" and, I presume the transactionManager is a JDBC (or JTA) transaction manager.

You also need to remove <queue/> from JmsInChannel so that the database transaction occurs on the same thread.

Spring will synchronize the database transaction with the JMS transaction.

However, read http://www.javaworld.com/javaworld/jw-01-2009/jw-01-spring-transactions.html for the implications.

If you can't make your service idempotent, you may need to look at an XA transaction manager.



来源:https://stackoverflow.com/questions/10451728/transaction-handling-while-using-message-driven-channel-adapter-service-activa

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