org.springframework.batch.integration.launch.JobLaunchRequest Java Examples

The following examples show how to use org.springframework.batch.integration.launch.JobLaunchRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IntegrationConfiguration.java    From building-microservices with Apache License 2.0 6 votes vote down vote up
@Bean
IntegrationFlow batchJobFlow(Job job,
                             JdbcTemplate jdbcTemplate,
                             JobLauncher launcher,
                             MessageChannel files) {

    return IntegrationFlows.from(files)
            .transform((GenericTransformer<Object,JobLaunchRequest>) file -> {
                System.out.println(file.toString());
                System.out.println(file.getClass());
                return null ;
            })
            .transform((GenericTransformer<File, JobLaunchRequest>) file -> {
                JobParameters jp = new JobParametersBuilder()
                        .addString("file", file.getAbsolutePath())
                        .toJobParameters();
                return new JobLaunchRequest(job, jp);
            })
            .handle(new JobLaunchingGateway(launcher))
            .handle(JobExecution.class, (payload, headers) -> {
                System.out.println("job execution status: " + payload.getExitStatus().toString());

                List<Person> personList = jdbcTemplate.query("select * from PEOPLE",
                        (resultSet, i) -> new Person(resultSet.getString("first"),
                                resultSet.getString("last"),
                                resultSet.getString("email")));

                personList.forEach(System.out::println);
                return null;
            })
            .get();

}
 
Example #2
Source File: EtlFlowConfiguration.java    From messaging with Apache License 2.0 5 votes vote down vote up
@Bean
IntegrationFlow etlFlow(
 @Value("${input-directory:${HOME}/Desktop/in}") File directory,
 BatchChannels c, JobLauncher launcher, Job job) {

 return IntegrationFlows
  .from(Files.inboundAdapter(directory).autoCreateDirectory(true),
   cs -> cs.poller(p -> p.fixedRate(1000)))
  .handle(
   File.class,
   (file, headers) -> {

    String absolutePath = file.getAbsolutePath();
	 	 // <2>
    JobParameters params = new JobParametersBuilder().addString("file",
     absolutePath).toJobParameters();

    return MessageBuilder.withPayload(new JobLaunchRequest(job, params))
     .setHeader(ORIGINAL_FILE, absolutePath)
     .copyHeadersIfAbsent(headers).build();
   })
 // <3>
  .handle(new JobLaunchingGateway(launcher))
 // <4>
  .routeToRecipients(
   spec -> spec.recipient(c.invalid(), this::notFinished).recipient(
    c.completed(), this::finished)).get();
}
 
Example #3
Source File: FolderListener.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
private void initTransformer() {
    this.transformer = new AbstractFilePayloadTransformer<JobLaunchRequest>() {
        @Override
        protected JobLaunchRequest transformFile(final File file) {
            FolderListener.this.attachFileSourceToJobParameters(file);
            return new JobLaunchRequest(FolderListener.this.job, FolderListener.this.jobParameters);
        }
    };
}
 
Example #4
Source File: FileMessageToJobRequest.java    From spring-batch-performance-tuning with Apache License 2.0 5 votes vote down vote up
public JobLaunchRequest toRequest(Message<File> message) {
	JobParametersBuilder jobParametersBuilder =
			new JobParametersBuilder();

	jobParametersBuilder
			.addString(fileName, message.getPayload().getAbsolutePath())
			.addDate("run.date", new Date());

	return new JobLaunchRequest(job, jobParametersBuilder.toJobParameters());
}