【问题标题】:Asynchronous Spring Batch Job multiple steps flow control异步 Spring Batch Job 多步流程控制
【发布时间】:2015-11-20 18:33:22
【问题描述】:

我有一个配置为异步运行的 spring 批处理作业(从 Web 服务启动并使用注释将方法配置为异步)我的第一步成功运行。

我的问题是我配置了多个步骤,并且流程是根据步骤的状态确定的,即在完成时它移动到步骤 2,但在失败时它移动到发送邮件的故障处理步骤。当删除注释时,流程似乎按预期工作。但是,当我使用注释异步运行作业时,配置为在完成时执行的任何步骤都会被执行。 流配置示例:

<batch:job id="batchJob" restartable="true">
    <batch:step id="step1">
        <batch:tasklet ref="task1">
            <batch:listeners>
                <batch:listener ref="failureHandler" />
            </batch:listeners>
        </batch:tasklet>
        <batch:next on="HAS_ERRORS" to="reportError" />
        <batch:end on="*" />
        <batch:next on="COMPLETED" to="step2" />
    </batch:step>
    <batch:step id="step2">
        <batch:tasklet ref="task2">
            <batch:listeners>
                <batch:listener ref="failureHandler" />
            </batch:listeners>
        </batch:tasklet>
        <batch:next on="HAS_ERRORS" to="reportError" />
        <batch:end on="*" />            
    </batch:step>
    <batch:step id="reportError">
        <batch:tasklet ref="failError">
            <batch:listeners>
                <batch:listener ref="failureHandler" />
            </batch:listeners>
        </batch:tasklet>
        <batch:end on="*" />
    </batch:step>
</batch:job>

我已尝试返回已被忽略的 ExitStatus 和 BatchStatus。

我已经实现了一个步骤执行侦听器,但我还没有实现一个消息传递机制来跨步骤进行通信,并且我在步骤执行上下文中看不到任何可以指示步骤结果的内容。

我的问题是,是否存在我可能忽略的方法或机制来获取步骤完成后的状态?还是批处理之外的消息传递机制是一种可接受的处理方式?

感觉错误的是,当批处理步骤异步完成后,我看不到它的状态(当我删除 @Async 注释时,我得到了预期的结果/失败)我认为可能有我的理解中缺少的东西我花了一些时间研究它,所以我们将不胜感激。

【问题讨论】:

  • 你能把添加注解的方法代码贴出来吗?

标签: spring asynchronous batch-processing


【解决方案1】:

我无法再访问此特定代码。

我认为这个问题是由覆盖定义预期流程的 XML 配置的注释引起的。

通过覆盖它,我们改变了我们预期的实际流程。

【讨论】:

  • 如果下次我注意到此问题时没有给出答案,我将标记为已接受,除非版主另有建议
猜你喜欢
  • 2017-06-10
  • 1970-01-01
  • 2020-11-21
  • 2013-07-12
  • 1970-01-01
  • 1970-01-01
  • 2019-10-17
  • 2013-01-05
  • 2022-01-03
相关资源
最近更新 更多