Reputation: 1
I hope you had great holidays.
I'm working on a little project right now, and I need your help.
I want to dynamically pass information from a parent step to its child steps.
I have a Spring Batch step (StepLevel1) that creates another step (StepLevel2) via a flow. I want to pass information (a string would be enough) from StepLevel1 to StepLevel2. Each StepLevel2 instance should know its parent via a value that differs in each instance of StepLevel1.
Example:
StepLevel1 Instance A gets the Step1Id = "1" via the partitioner (doesn't need to be).
StepLevel1 Instance B gets the Step1Id = "2" via the partitioner (doesn't need to be).
StepLevel1 Instance A creates multiple StepLevel2 instances (C, D, E, F), all having the information Step1Id = "1".
StepLevel1 Instance B creates multiple StepLevel2 instances (G, H, I, J), all having the information Step1Id = "2".
I have a dynamic number of StepLevel1 and StepLevel2 instances.
@Autowired
@Qualifier("StepLevel2")
@Lazy
private Step StepLevel2;
@Bean(name = "StepLevel1")
@Lazy
public Step createStep() {
return new StepBuilder("step1", jobRepository)
.partitioner("step1Partition", partitioner())
.step(partitionedFlowStep())
.gridSize(getGridSize())//generated dynamically
.build();
}
@Bean
public Step partitionedFlowStep() {
return new StepBuilder("partitionedFlowStep", jobRepository)
.flow(partitionedFlow()).build();
}
@Bean
public Flow partitionedFlow() {
return new FlowBuilder<Flow>("partitionedFlow")
.start(doSomething())
.next(languageExportStepBean).end();
}
public Step doSomething() {
return new StepBuilder("doSomething", jobRepository).tasklet((contribution, chunkContext) -> {
//do Something
return RepeatStatus.FINISHED;
}, transactionManager).build();
}```
I tried saving the values in the StepExecutionContext but in the StepLevel2 the values disappeared. When saving it into the JobExecutionContext the values stay but the created StepLevel2s can not identify which Level1 Step created them.
Upvotes: 0
Views: 35
Reputation: 192
Partitioners have their own ExecutionContext which you can bind data for the slave steps https://docs.spring.io/spring-batch/reference/scalability.html#:~:text=The%20names%20show%20up%20later,location%20of%20an%20input%20file.
Upvotes: 0