我打算使用 Spring Batch。我们喜欢在响应前端请求的 pod 中启动新的作业执行。
伪代码:
@PostMapping(path = "/request-report/{id}")
public void requestReport(String id){
this.jobOperator.start("reportJob", new Properties("1"));
}
但我们不希望作业在前端 pod 中执行。为此,我们喜欢构建一个单独的微服务 pod。
我看到以下解决方案:
从前端 pod 到 spring-batch pod 进行一次休息调用,然后在那里开始工作。我可以这样做,但如果可能的话,我想跳过该步骤并将其集成到 Spring Batch 数据库中。
在前端 pod 中,我创建了具有大小为零的 SimpleAsyncTaskExecutor 的 JobLauncher。所以它永远不会执行作业。
https://docs.spring.io/spring-batch/docs/current/reference/html/job.html#configuringJobLauncher
@Bean
public JobLauncher jobLauncher() {
SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
jobLauncher.setJobRepository(jobRepository());
jobLauncher.setTaskExecutor(new SimpleAsyncTaskExecutor());
jobLauncher.afterPropertiesSet();
return jobLauncher;
}
- 在前端 pod 中,我不使用 BatchAutoConfiguration 而是留下一些东西,但是什么?
我想我还必须编写一些软件来扫描作业表并检查是否存在未启动的作业,并再次在 spring-batch-pod 中启动。
谢谢你的帮助!