Spring Integration, JMS Inbound channel adaptor and transactions
I am using SI configured with a jms:message-driven-channel-adapter. My use case is to receive a message from the queue, save it via JDBC to a database, commit the message from the queue, and then let this message continue to flow through the various channels depending on its type. If the message subsequently errors this is ok as I have the original stored in the database so it can be replayed.
My issue is with trying to commit the transaction from the queue immediately after the database persist. This is effectively mid flow and I have only been able to get the spring transaction management to try and commit right at the end. This is not suitable as if an error is thrown after the database persist it still leaves the message on the JMS queue, as this is where the oute开发者_开发知识库r transaction originated.
So, is there an easy way to pull the message from a JMS queue, save to database, then commit it off the queue and start a new transaction for the remaining flow?
Thanks!
Rich
You can save to the database and then put the message in a pollable channel:
<channel id="aChannel">
<queue capacity="10"/>
</channel>
This will make any subsequent flow to be in a new transaction, as the new flow will be handled by a different thread - based on the poller that you associate with this pollable channel.
精彩评论