【问题标题】:How to guarantee that job is finished before starting the next step of IntegrationFlow?如何保证在开始IntegrationFlow 的下一步之前完成该工作?
【发布时间】:2020-01-09 04:03:18
【问题描述】:

我有以下流声明:

return flow -> flow.handle(myHandler)                
                .handle(springBatchJobLauncher)              
                .gateway(acknowledgementFlow);

启动器如下所示:

@ServiceActivator
public JobExecution launch(JobLaunchRequest request) throws JobExecutionException {
    Job job = request.getJob();
    JobParameters jobParameters = request.getJobParameters();

    return jobLauncher.run(job, jobParameters);
}

springBatchJobLauncher 开始的工作完成后,我需要立即开始acknowledgementFlow。按照这个配置有保障吗?

【问题讨论】:

  • 我认为如果您的作业启动器是同步的,它应该可以按您的预期工作。
  • @Mahmoud Ben Hassine 实际上是这样,但我担心以后工作可能会改变,一切都会被打破

标签: java spring-boot spring-integration spring-batch spring-integration-dsl


【解决方案1】:

让我们来看看JobLauncher.run()JavaDocs!

 * Start a job execution for the given {@link Job} and {@link JobParameters}
 * . If a {@link JobExecution} was able to be created successfully, it will
 * always be returned by this method, regardless of whether or not the
 * execution was successful. If there is a past {@link JobExecution} which
 * has paused, the same {@link JobExecution} is returned instead of a new
 * one created. A exception will only be thrown if there is a failure to
 * start the job. If the job encounters some error while processing, the
 * JobExecution will be returned, and the status will need to be inspected.

因此,如果作业已成功启动,您将获得一个JobExecution 对象,但这确实与您的作业是否完成无关。为了这个目标,我相信我们需要有类似JobExecutionListener 的钩子。

在 Spring Batch 文档中查看更多信息:https://docs.spring.io/spring-batch/4.2.x/reference/html/spring-batch-integration.html#providing-feedback-with-informational-messages

step 有一个示例:

@MessagingGateway(name = "notificationExecutionsListener", defaultRequestChannel = "stepExecutionsChannel")
public interface NotificationExecutionListener extends StepExecutionListener {}

但同样的方法可以应用于JobExecutionListener

因此,您需要将您的流程分成两部分,并让您的 .gateway(acknowledgementFlow) 仅从您的工作中执行的 afterJob(JobExecution jobExecution) 调用。

【讨论】:

  • 当你输入 你需要将你的流程分成两个并有你的时你是什么意思?
  • 我想我必须在 afterJob 中调用 acknowledgementFlow
  • 您的第一个流程必须使用作业启动器完成。第二个流程可以从监听接口上网关发起的通道开始
猜你喜欢
  • 2020-04-24
  • 1970-01-01
  • 2011-11-28
  • 1970-01-01
  • 2018-05-22
  • 2017-09-14
  • 1970-01-01
  • 2020-06-18
  • 1970-01-01
相关资源
最近更新 更多