简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM