用于多个节点的 spring 集成 jdbc 适配器 [英] spring integration jdbc adapter for multiple nodes

查看:21
本文介绍了用于多个节点的 spring 集成 jdbc 适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 jdbc inbound-channel-adapter 和如下典型配置来从 MYSQL DB 中检索记录.问题是如何让jdbc inbound-channel-adapter在多节点环境下工作?不同的节点将有机会获得一个相同的记录进行处理.我知道这可能是一个老问题,但到目前为止我找不到解决方案.

I'm using the jdbc inbound-channel-adapter with a typical configuration as below to retrieve records from MYSQL DB. The question is how to make the jdbc inbound-channel-adapter work in a multiple nodes environment? Different nodes will have chance to get one same record to process. I know this may be a old questions but I cannot find the resolution so far.

<int-jdbc:inbound-channel-adapter query="select * from messages where state='NEW'"
    channel="jdbcChannel" data-source="datasource" update="update messages set state='PROCESSING' where id in (:id)"
    row-mapper="messageRowMapper" max-rows-per-poll="1">
</int-jdbc:inbound-channel-adapter>

推荐答案

是的,你应该为 提供事务,正如 Gary 所指出的,但此外你应该保证一个事务将阻塞另一个直到它完成.为此,您应该为您的 SELECT 提供 FOR UPDATELOCK IN SHARE MODE 提示.

Yes, you should supply transactions for the <poller> as Gary pointed, but in addition you should guaranty that one transaction will block another until it finishes. For this purpose you should supply your SELECT with FOR UPDATE or LOCK IN SHARE MODE hints.

更多信息在 MySQL 文档 或在此答案中:MySQL '选择更新'行为.

More info is in MySQL Docs or in this answer: MySQL 'select for update' behaviour .

这篇关于用于多个节点的 spring 集成 jdbc 适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆