gpt4 book ai didi

spring - 判断spring integration中一个循环工作流的结束(inbound-channel => service-activator)

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

我们有以下基于 int-jpa 的简单工作流:

[入站 channel 适配器] -> [服务激活器]

配置是这样的:

<int:channel id="inChannel">  <int:queue/> </int:channel>
<int:channel id="outChannel"> <int:queue/> </int:channel>
<int-jpa:inbound-channel-adapter id="inChannelAdapter" channel="inChannel"
jpa-query="SOME_COMPLEX_POLLING_QUERY"
max-results="2">
<int:poller max-messages-per-poll="2" fixed-rate="20" >
<int:advice-chain synchronization-factory="txSyncFactory" >
<tx:advice transaction-manager="transactionManager" >
<tx:attributes>
<tx:method name="*" timeout="30000" />
</tx:attributes>
</tx:advice>
<int:ref bean="pollerAdvice"/>
</int:advice-chain>
</int-jpa:inbound-channel-adapter>

<int:service-activator input-channel="inChannel" ref="myActivator"
method="pollEntry" output-channel="outChannel" />

<bean id="myActivator" class="com.company.myActivator" />
<bean id="pollerAdvice" class="com.company.myPollerAdvice" />

处理的入口点是一个不断增长的表,SOME_COMPLEX_POLLING_QUERY 针对该表运行。当前流程是:

  1. [Thread-1] SOME_COMPLEX_POLLING_QUERY 将仅返回将 busy 设置为 false 的条目(我们使用 txSyncFactory 完成轮询后,立即将 busy 设置为 true)
  2. [Thread-2] 这些条目将通过 myActivator,可能需要 1 分钟到 30 分钟。
  3. [Thread-2] 处理完成后,我们将 busytrue 设置回 false

问题:即使表中所有条目的处理都已完成,我们也需要触发通知。

尝试的方法:我们使用pollerAdviceafterReturning 来查明SOME_COMPLEX_POLLING_QUERY 是否返回任何结果或不是。但是,此方法将在 Thread-2 处理完所有条目之前开始返回“无条目”方式。

注意:

  • 相同的条目将在 24 小时后再次处理。但是这次它会有更多条目。
  • 我们没有使用 outbound-channel-adapter,因为我们对它没有任何要求。但是,如果这是提议的解决方案的一部分,我们愿意使用它。

最佳答案

不确定这是否适合您,但由于您仍然需要等待通知直到 Thread-2 , 我建议有一些 AtomicBoolean bean 。在提到的afterReturning() ,当没有从数据库中轮询数据时,您只需更改 AtomicBoolean 的状态即可至 true .当 Thread-2完成它的工作,它可以调用<filter>检查 AtomicBoolean 的状态然后真正执行<int-event:outbound-channel-adapter>发出通知事件。

因此,是否发出事件的最终决定肯定是从 Thread-2 开始的。 ,而不是轮询 channel 适配器。

关于spring - 判断spring integration中一个循环工作流的结束(inbound-channel => service-activator),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49651814/

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