Spring Batch Partitioning с несколькими шагами, запущенными последовательно? - PullRequest
0 голосов
/ 30 ноября 2018

У меня есть требование создать главный шаг с несколькими последовательными шагами подчиненных.Я могу определить одно подчиненное устройство внутри главного устройства, но мне нужно последовательно запустить подчиненные устройства.

@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();
}

Есть ли способ определить несколько этапов подчиненных устройств в одном главном шаге под одним и тем же разделителем, как показано ниже?

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
)                 {}

введите описание изображения здесь

1 Ответ

0 голосов
/ 03 декабря 2018

Мне просто нужно определить поток внутри шага раба.Этот поток будет работать как последовательный.Шаг Раба - не что иное, как определение всех дочерних Шагов внутри.Таким образом, все подчиненные шаги выполняются параллельно, и каждый подчиненный выполняет дочерние подчиненные шаги последовательно.

/**
 * @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
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...