使用注释配置并行(拆分)的Spring批处理步骤 [英] Configuring Spring Batch Steps in Parallel (Split) using Annotations
问题描述
无论我在哪里查看Spring Batch文档以并行执行步骤,我只能通过XML看到它的配置,如下所示。
Where ever I look into Spring Batch documentation for executing steps in parallel, I only see the configuration of it via XML like given below.
<split id="split1" next="step4">
<flow>
<step id="step1" parent="s1" next="step2"/>
<step id="step2" parent="s2"/>
</flow>
<flow>
<step id="step3" parent="s3"/>
</flow>
我正在编写一个申请表Spring Batch也使用了Spring Boot,我的所有配置都是使用Annotations完成的。有没有我可以使用Java配置配置Split Step?我检查了API 文档 Spring Batch中的Step接口,但它没有Split Step的默认实现。有没有办法可以使用现有的默认实现来实现它?
I am writing an application using Spring Batch where I have used Spring Boot as well, and all of my configurations are done using Annotations. Is there a I can configure a Split Step using Java configuration? I checked the API documentation of Step interface in Spring Batch, but it doesn't have a default implementation for Split Step. Is there way I can implement it using the existing default implementations?
目前我已经实现了我的其他工作:
Currently I have implemented my other jobs like this :
@Bean
public Step someStep() {
return stepBuilderFactory.get("someStep")
.<A, B> chunk(1-).reader(someReader)
.processor(someProcessor).writer(someWriter).build();
}
@Bean
public Job historicalDataJob() {
return jobBuilderFactory.get("someJOb")
.incrementer(new RunIdIncrementer()).flow(someStep()).end()
.build();
}
推荐答案
SimpleJobBuilder
提供了通过java配置配置拆分的工具。下面是一个来自 FlowJobBuilderTests
的示例( https://github.com/spring-projects/spring-batch/blob/master /spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowJobBuilderTests.java )。显然你会想要解决这个问题,但它应该说明一般的想法。
The SimpleJobBuilder
provides facilities for configuring a split via java config. Below is an example taken from the FlowJobBuilderTests
(https://github.com/spring-projects/spring-batch/blob/master/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowJobBuilderTests.java). Obviously you'll want to break this up a bit, but it should illustrate the general idea.
// Create each flow
Flow flow = new FlowBuilder<Flow>("subflow").from(step1).end();
// Create the job
SimpleJobBuilder builder = new JobBuilder("flow").repository(jobRepository).start(step2);
// Create split providing an async task executor so the flows are executed in parallel
builder.split(new SimpleAsyncTaskExecutor()).add(flow).end();
// Build the job and execute it
builder.preventRestart().build().execute(execution);
这篇关于使用注释配置并行(拆分)的Spring批处理步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!