简体   繁体   English

Spring批处理分区有多个顺序运行?

[英]Spring batch Partitioning with multiple steps running in Sequentially?

I have requirement to create a master step with multiple Slaves steps running sequentially. 我需要创建一个依次运行多个从属步骤的主步骤。 I am able to define single slave inside in master but I need to run slaves sequentially. 我可以在主机中定义单个从机,但是我需要顺序运行从机。

@Primary
@Profile(MASTER)
@Bean("masterStep")
public Step partitionCreateStepForRemote(StepBuilderFactory stepBuilderFactory,
                            @Qualifier("slave1") Step step,
                            MatchAsyncConfig asyncConfig,
                            MatchingAccountPartitioner partitioner,
                            JMSPartitionHandler messageChannelPartitionHandler,
                            JobRepository jobRepository,
                            @Qualifier("stepLocator") StepLocator stepLocator
)                 {

 SimpleStepExecutionSplitter splitter = new SimpleStepExecutionSplitter();
splitter.setPartitioner(partitioner);
splitter.setJobRepository(jobRepository);

return stepBuilderFactory.get("masterStep")
        .partitioner(step)
        .partitionHandler(messageChannelPartitionHandler)
        .splitter(splitter)
        .taskExecutor(asyncConfig.getAsyncExecutor())
        .build();
}

Is There any way to define multiple slaves steps in single master step under same partitioner like below? 有没有办法在同一个分区下的单个主步骤中定义多个从步骤,如下所示?

public Step partitionCreateStepForRemote(StepBuilderFactory stepBuilderFactory,
                            @Qualifier("slave1") Step step,
                            @Qualifier("slave2") Step step,
                            @Qualifier("slave3") Step step, 
                            MatchAsyncConfig asyncConfig,
                            MatchingAccountPartitioner partitioner,
                            JMSPartitionHandler messageChannelPartitionHandler,
                            JobRepository jobRepository,
                            @Qualifier("stepLocator") StepLocator stepLocator
)                 {}

enter image description here 在此处输入图片说明

I just need to define Flow inside of slave step. 我只需要在从属步骤内部定义Flow。 That flow will works as sequential. 该流程将按顺序进行。 Slave Step is nothing but defining all child Steps internally. 从属步骤不过是在内部定义所有子步骤而已。 So all Slave Steps are running parallel and each slave is running Child Slave Steps sequential. 因此,所有从属步骤均并行运行,每个从属均顺序运行子级从属步骤。

/**
 * @param stepBuilderFactory   step for run each partition
 * @return Step step 6 partition match
 */
@Profile({SINGLE, SLAVE})  //Not applicable for MASTER profile in remote partitioning case
@Bean("slaveStep")
public Step slaveStep(StepBuilderFactory stepBuilderFactory,
                               @Qualifier("readFromFileFlow") Flow flow
) {
    return stepBuilderFactory.get("slaveStep")
            .listener(stepListener())
            .flow(flow)
            .build();
}

@Profile({SINGLE, SLAVE})
@Bean
public ChildSlaveListener stepListener(){
    return new ChildSlaveListener();
}

@Profile({SINGLE, SLAVE})
@Bean("readFromFileFlow")
public Flow readFromFileFlow(@Qualifier("childSlaveStep1") Step childSlaveStep1,
                             @Qualifier("childSlaveStep2") Step childSlaveStep2) {
    // @formatter:off
    return new FlowBuilder<Flow>("readFromFileFlow")
            .start(childSlaveStep1)
            .on(FAILED).fail()
            .from(childSlaveStep1)
            .on(COMPLETED).to(childSlaveStep2)
            .start(childSlaveStep2)
            .on(FAILED).fail()
            .from(childSlaveStep2)
            .on(COMPLETED).end()
            .end();
    // @formatter:on
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM