如何使用决策器终止Spring批处理拆分流中的步骤 [英] How to terminate Step within a Spring Batch Split Flow with a Decider

查看:14
本文介绍了如何使用决策器终止Spring批处理拆分流中的步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Spring Batch中出现了以下设计缺陷。

  1. 步骤必须具有Next属性,除非它是拆分流的最后一步或最后一步。
  2. 决定者挡路必须处理决定者返回的所有案例。
正因为如此,在拆分流中,最后一步不会有NEXT属性,如果有决策器守卫它,那么它必须有NEXT属性。所以它不应该有这个属性,但是它也需要这个属性。第22条。

示例:

<!-- Process parallel steps -->
<split id="split01">
    <flow>
        <step id="step1" next="step02">
            <!-- Do something -->
        </step>
        <step id="step02">
            <!-- Do something else -->
        </step>
    </flow>
    <flow>
        <step id="step03">
            <!-- Do something -->
        </step>

        <!-- Only run under specific conditions -->
        <decision id="decideToRunStep04" decider="isStepNeededDecider" >
            <next on="RUN" to="step04"/>
            <!-- Other state is "SKIP" -->
        </decision>
        <step id="step04">
            <!-- Conditionally do something-->
        </step>
    </flow>
</split>

<step id="step05" >
    <!-- Some more stuff -->
</step>

这似乎是Spring的人会想到的事情,所以很好奇实现这一点的正确的、非黑客的方式是什么。谢谢。

推荐答案

任何人都没有回答这个问题,我将提供我正在使用的黑客攻击。它不漂亮,但是春天也不漂亮。

创建在"无操作"步骤中使用的"无操作"Tasklet。

public class NoopTasklet implements Tasklet {
    @Override
    public RepeatStatus execute(final StepContribution contribution,
            final ChunkContext chunkContext) throws Exception {
        return RepeatStatus.FINISHED;
    }
}

将NOOP微线程添加到原始示例中的决策挡路

<!-- Does nothing -->
<bean id="noopTasklet" class="com.foo.NoopTasklet" />

<!-- From example in question
<decision id="decideToRunStep04" decider="isStepNeededDecider" >
    <next on="RUN" to="step04"/>
    <next on="SKIP" to="noop01"/>
</decision>
<step id="step04">
    <!-- Conditionally do something-->
</step>
<step id="noop01">
    <!-- Does nothing in the SKIP case
    <tasklet ref="noopTasklet" />
</step>

这篇关于如何使用决策器终止Spring批处理拆分流中的步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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