简体   繁体   中英

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. 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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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