Spring Integration、JMS 入站通道适配器和事务
我正在使用配置有 jms:message-driven-channel-adapter 的 SI。我的用例是从队列接收消息,通过 JDBC 将其保存到数据库,从队列提交消息,然后让该消息根据其类型继续流经各个通道。如果消息随后出错,这没关系,因为我将原始消息存储在数据库中,以便可以重播。
我的问题是在数据库持久化后尝试立即从队列提交事务。这实际上是中间流程,我只能让 Spring 事务管理在最后尝试并提交。这是不合适的,因为如果在数据库持久化后抛出错误,它仍然会将消息留在 JMS 队列上,因为这是外部事务的起源处。
那么,是否有一种简单的方法可以从 JMS 队列中提取消息,保存到数据库,然后将其从队列中提交,并为剩余流启动一个新事务?
谢谢!
富有的
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以保存到数据库,然后将消息放入可轮询通道中:
这将使任何后续流都位于新事务中,因为新流将由不同的线程处理 - 基于与此关联的轮询器可轮询的通道。
You can save to the database and then put the message in a pollable 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.