简体   繁体   English

Spring Integration,JMS入站通道适配器和事务

[英]Spring Integration, JMS Inbound channel adaptor and transactions

I am using SI configured with a jms:message-driven-channel-adapter. 我正在使用配置有jms:message-driven-channel-adapter的SI。 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. 我的用例是从队列中接收一条消息,通过JDBC将其保存到数据库,从队列中提交该消息,然后让该消息根据其类型继续流经各个通道。 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. 这实际上是中间流程,我只能让Spring事务管理在最后尝试并提交。 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. 这不适合,因为在数据库持久化之后仍然抛出错误,它仍然将消息保留在JMS队列上,因为这是外部事务的起源。

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? 因此,是否有一种简单的方法可以从JMS队列中提取消息,将其保存到数据库,然后将其提交出队列并为剩余的流启动新的事务?

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. 这将使任何后续流程进入新事务,因为新流程将由不同的线程处理-基于与该可轮询通道关联的轮询器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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