gpt4 book ai didi

spring-integration - inbound-channel-adapter - 如何在失败时更新行字段?

转载 作者:行者123 更新时间:2023-12-02 01:49:30 26 4
gpt4 key购买 nike

我有一个从标准数据库查询开始的集成,它会更新数据库中的状态以表明集成工作正常。有用。

但是如果无法处理数据并引发异常,则状态不会按预期更新,但我想用“KO”状态更新我的数据库行,这样同一行就不会一遍又一遍地失败.

有没有办法在集成失败时提供第二个查询来执行?

在我看来,这是一种非常标准的做事方式,但我找不到一种简单的方法来做到这一点。我可以在集成的每个步骤中捕获异常并更新数据库,但它会产生耦合,因此应该有另一种解决方案。

我尝试了很多 Google 搜索,但找不到任何东西,但我很确定答案就在那里。

以防万一,有我的 xml 配置来执行数据库查询(没什么特别的):

<int-jdbc:inbound-channel-adapter auto-startup="true" data-source="datasource"
query="select * FROM MyTable where STATE='ToProcess')"
channel="stuffTransformerChannel"
update="UPDATE MyTable SET STATE='OK' where id in (:id)"
row-mapper="myRowMapper" max-rows-per-poll="1">
<int:poller fixed-rate="1000">
<int:transactional />
</int:poller>
</int-jdbc:inbound-channel-adapter>

我正在使用 spring-integration 版本 4.0.0.RELEASE

最佳答案

由于您在事务中,这是正常行为,导致回滚并且您的数据库返回到清除状态。

在这种情况下,基于应用目的处理数据是经典模式,而不是来自某些内置工具。这就是我们不提供任何 on-error-update 的原因,因为它不能成为所有事物的用例。

无论如何,只要您要更新行,您就应该在 onRallback 事件上做一些事情,并在新事务中做这件事。但是它应该在同一个线程中,以防止从第二个轮询任务中获取同一行。

为此,我们提供了一个transaction-synchronization-factory 功能:

<int-jdbc:inbound-channel-adapter max-rows-per-poll="1">
<int:poller fixed-rate="1000" max-messages-per-poll="1">
<int:transactional synchronization-factory="syncFactory"/>
</int:poller>
</int-jdbc:inbound-channel-adapter>

<int:transaction-synchronization-factory id="syncFactory">
<int:after-rollback channel="stuffErrorChannel"/>
</int:transaction-synchronization-factory>

<int-jdbc:outbound-channel-adapter
query="UPDATE MyTable SET STATE='KO' where id in (:payload[id])"
channel="stuffErrorChannel">
<int-jdbc:request-handler-advice-chain>
<tx:advice id="requiresNewTx">
<tx:attributes>
<tx:method name="handle*Message" propagation="REQUIRES_NEW"/>
</tx:attributes>
</tx:advice>
</int-jdbc:request-handler-advice-chain>
</int-jdbc:outbound-channel-adapter>

希望我清楚

关于spring-integration - inbound-channel-adapter - 如何在失败时更新行字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23675483/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com