为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

郎朗坤 2023-07-13 14:33:29
我有以下流程声明:return flow -> flow.handle(myHandler)                                .handle(springBatchJobLauncher)                              .gateway(acknowledgementFlow);启动器看起来像这样:@ServiceActivatorpublic JobExecution launch(JobLaunchRequest request) throws JobExecutionException {    Job job = request.getJob();    JobParameters jobParameters = request.getJobParameters();    return jobLauncher.run(job, jobParameters);}我需要acknowledgementFlow在开始的工作完成后立即开始springBatchJobLauncher。按照这个配置能保证吗?
查看完整描述

1 回答

?
梦里花落0921

TA贡献1772条经验 获得超5个赞

让我们看一下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)您的工作中执行的任务中进行调用。


查看完整回答
反对 回复 2023-07-13
  • 1 回答
  • 0 关注
  • 73 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信