如何保证该工作在开始IntegrationFlow的下一步之前完成?

我有以下流程声明:


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);

}

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


郎朗坤
浏览 74回答 1
1回答

梦里花落0921

让我们看一下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对象,但这实际上与您的工作是否完成无关。为了实现这个目标,我相信我们需要像JobExecutionListenerhook 这样的东西。有一个示例step:@MessagingGateway(name = "notificationExecutionsListener", defaultRequestChannel = "stepExecutionsChannel")public interface NotificationExecutionListener extends StepExecutionListener {}但同样的方法也适用于JobExecutionListener.因此,您需要将流程分成两部分,并.gateway(acknowledgementFlow)仅从afterJob(JobExecution jobExecution)您的工作中执行的任务中进行调用。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java