I am trying to process a series of files using Spring Integration in a batch fashion. I have this very old xml which tries to convert the messages into jobs
<int:transformer ref="messageToJobTransformer"/>
<batch-int:job-launching-gateway job-launcher="jobLauncher"/>
The messageToJobTransformer
is a class which can convert a Message into a Job. The problem is I don't know where this file is now neither I want a xml config. I want it to be pure Java DSL. Here is my simple config.
return IntegrationFlows.from(Files.inboundAdapter(directory)
.preventDuplicates()
.patternFilter("*.txt")))
.handle(jobLaunchingGw())
.get();
And here is my bean for the gateway.
@Autowired
private JobLauncher jobLauncher;
@Bean
public MessageHandler jobLaunchingGw() {
return new JobLaunchingGateway(jobLauncher);
}
EDIT:Updating the Batch Config class.
@Configuration
@EnableBatchProcessing
public class BatchConfig
{
@Autowired
private JobBuilderFactory jobs;
@Autowired
private StepBuilderFactory steps;
@Bean
public ItemReader<String> reader(@Value({jobParameters['input.file.name']}") String filename) throws MalformedURLException
{
FlatFileItemReader<String> reader = new FlatFileItemReader<String>();
return reader;
}
@Bean
public Job job() throws MalformedURLException
{
return jobs.get("job").start(step()).build();
}
@Bean
public Step step() throws MalformedURLException
{
return steps.get("step").<String, String> chunk(5).reader(reader())
.writer(writer()).build();
}
@Bean
public ItemWriter<String> writer(@Value("#{jobParameters['input.file.name']}")
{
FlatFileItemWriter writer = new FlatFileItemWriter();
return writer;
}
}
Your question isn't clear. The
JobLaunchingGateway
expectsJobLaunchRequest
as apayload
.Since your Integration Flow begins from the
Files.inboundAdapter(directory)
, I can assume that you that you have there some Job definitions. So, what you need here is some class which can parse the file and returnJobLaunchRequest
.Something like this from the Spring Batch Reference Manual:
After the definition that class as a
@Bean
you can use it from the.transform()
EIP-method just before your.handle(jobLaunchingGw())
.UPDATE