【问题标题】:Determine the end of a cyclic workflow in spring integration (inbound-channel => service-activator)确定 spring 集成中循环工作流的结束(入站通道 => 服务激活器)
【发布时间】:2018-09-14 01:30:59
【问题描述】:

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

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

配置是这样的:

<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 来确定@​​987654335@ 是否返回任何结果。但是,此方法将在 Thread-2 处理完所有条目之前开始返回“No Entries”。

注意:

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

【问题讨论】:

    标签: spring spring-data-jpa spring-integration


    【解决方案1】:

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

    因此,是否发出事件的最终决定肯定由Thread-2 完成,而不是轮询通道适配器。

    【讨论】:

    • 谢谢阿特姆。但是,不确定我们如何知道 Thread-2 何时完成其工作
    • 嗯,这不是你在outChannel 中得到的吗?你自己说:Once the processing is done。所以,看起来你知道发生了什么
    • 还有一点需要注意:如果有来自 DB 的轮询消息,您需要将 AtomicBoolean 标志重置为 false,对于 Thread-2 来说意味着“未完成”
    • 好吧,现在我没有使用注释中提到的outChannelOnce the processing is done 我的意思是 myActivator 本身,我们调用 DB 并将标志设置为 false
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-15
    • 2013-01-08
    相关资源
    最近更新 更多