Java Code Examples for org.springframework.batch.core.configuration.annotation.StepBuilderFactory

The following examples show how to use org.springframework.batch.core.configuration.annotation.StepBuilderFactory. These examples are extracted from open source projects. 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 Project: building-microservices   Source File: BatchConfiguration.java    License: Apache License 2.0 7 votes vote down vote up
@Bean
Job personEtl(JobBuilderFactory jobBuilderFactory,
        StepBuilderFactory stepBuilderFactory,
        FlatFileItemReader<Person> reader,
        JdbcBatchItemWriter<Person> writer
) {

    Step step = stepBuilderFactory.get("file-to-database")
            .<Person, Person>chunk(5)
            .reader(reader)
            .writer(writer)
            .build();

    return jobBuilderFactory.get("etl")
            .start(step)
            .build();
}
 
Example 2
@Bean(name = STEP_PROCESS_CSV_FILE)
public Step readCsvFileAndPopulateDbTable(
        StepBuilderFactory stepBuilderFactory,
        PlatformTransactionManager platformTransactionManager,
        @Qualifier(DATA_READER) ItemReader<JavaChampion> itemReader,
        @Qualifier(DATA_PROCESSOR) ItemProcessor<JavaChampion, JavaChampion> itemProcessor,
        @Qualifier(DATA_WRITER) ItemWriter<JavaChampion> itemWriter) {

    StepBuilder builder = stepBuilderFactory.get(STEP_PROCESS_CSV_FILE);

    return builder.<JavaChampion, JavaChampion>chunk(10)
            .reader(itemReader)
            .processor(itemProcessor)
            .writer(itemWriter)
            .transactionManager(platformTransactionManager)
            .build();
}
 
Example 3
Source Project: SpringBootBucket   Source File: BudgetVtollConfig.java    License: MIT License 6 votes vote down vote up
/**
     * step步骤,包含ItemReader,ItemProcessor和ItemWriter
     *
     * @param stepBuilderFactory
     * @param reader
     * @param writer
     * @param processor
     * @return
     */
    @Bean(name = "vtollStep1")
    public Step vtollStep1(StepBuilderFactory stepBuilderFactory,
                           @Qualifier("vtollReader") ItemReader<BudgetVtoll> reader,
                           @Qualifier("vtollWriter") ItemWriter<BudgetVtoll> writer,
                           @Qualifier("vtollProcessor") ItemProcessor<BudgetVtoll, BudgetVtoll> processor) {
        return stepBuilderFactory
                .get("vtollStep1")
                .<BudgetVtoll, BudgetVtoll>chunk(5000)//批处理每次提交5000条数据
                .reader(reader)//给step绑定reader
                .processor(processor)//给step绑定processor
                .writer(writer)//给step绑定writer
                .faultTolerant()
                .retry(Exception.class)   // 重试
                .noRetry(ParseException.class)
                .retryLimit(1)           //每条记录重试一次
                .skip(Exception.class)
                .skipLimit(200)         //一共允许跳过200次异常
//                .taskExecutor(new SimpleAsyncTaskExecutor()) //设置每个Job通过并发方式执行,一般来讲一个Job就让它串行完成的好
//                .throttleLimit(10)        //并发任务数为 10,默认为4
                .build();
    }
 
Example 4
Source Project: SpringBootBucket   Source File: CantonConfig.java    License: MIT License 6 votes vote down vote up
/**
     * step步骤,包含ItemReader,ItemProcessor和ItemWriter
     *
     * @param stepBuilderFactory
     * @param reader
     * @param writer
     * @param processor
     * @return
     */
    @Bean(name = "cantonStep1")
    public Step cantonStep1(StepBuilderFactory stepBuilderFactory,
                           @Qualifier("cantonReader") ItemReader<Canton> reader,
                           @Qualifier("cantonWriter") ItemWriter<Canton> writer,
                           @Qualifier("cantonProcessor") ItemProcessor<Canton, Canton> processor) {
        return stepBuilderFactory
                .get("cantonStep1")
                .<Canton, Canton>chunk(5000)//批处理每次提交5000条数据
                .reader(reader)//给step绑定reader
                .processor(processor)//给step绑定processor
                .writer(writer)//给step绑定writer
                .faultTolerant()
                .retry(Exception.class)   // 重试
                .noRetry(ParseException.class)
                .retryLimit(1)           //每条记录重试一次
                .skip(Exception.class)
                .skipLimit(200)         //一共允许跳过200次异常
//                .taskExecutor(new SimpleAsyncTaskExecutor()) //设置每个Job通过并发方式执行,一般来讲一个Job就让它串行完成的好
//                .throttleLimit(10)        //并发任务数为 10,默认为4
                .build();
    }
 
Example 5
Source Project: SpringBootBucket   Source File: LogConfig.java    License: MIT License 6 votes vote down vote up
/**
     * step步骤,包含ItemReader,ItemProcessor和ItemWriter
     *
     * @param stepBuilderFactory
     * @param reader
     * @param writer
     * @param processor
     * @return
     */
    @Bean(name = "logStep1")
    public Step logStep1(StepBuilderFactory stepBuilderFactory,
                         @Qualifier("logReader") ItemReader<Log> reader,
                         @Qualifier("logWriter") ItemWriter<Log> writer,
                         @Qualifier("logProcessor") ItemProcessor<Log, Log> processor) {
        return stepBuilderFactory
                .get("logStep1")
                .<Log, Log>chunk(5000)//批处理每次提交5000条数据
                .reader(reader)//给step绑定reader
                .processor(processor)//给step绑定processor
                .writer(writer)//给step绑定writer
                .faultTolerant()
                .retry(Exception.class)   // 重试
                .noRetry(ParseException.class)
                .retryLimit(1)           //每条记录重试一次
                .skip(Exception.class)
                .skipLimit(200)         //一共允许跳过200次异常
//                .taskExecutor(new SimpleAsyncTaskExecutor()) //设置每个Job通过并发方式执行,一般来讲一个Job就让它串行完成的好
//                .throttleLimit(10)        //并发任务数为 10,默认为4
                .build();
    }
 
Example 6
Source Project: SpringBootBucket   Source File: AppConfig.java    License: MIT License 6 votes vote down vote up
/**
     * step步骤,包含ItemReader,ItemProcessor和ItemWriter
     *
     * @param stepBuilderFactory
     * @param reader
     * @param writer
     * @param processor
     * @return
     */
    @Bean(name = "zappStep1")
    public Step zappStep1(StepBuilderFactory stepBuilderFactory,
                          @Qualifier("appReader") ItemReader<App> reader,
                          @Qualifier("appWriter") ItemWriter<App> writer,
                          @Qualifier("appProcessor") ItemProcessor<App, App> processor) {
        return stepBuilderFactory
                .get("zappStep1")
                .<App, App>chunk(5000)//批处理每次提交5000条数据
                .reader(reader)//给step绑定reader
                .processor(processor)//给step绑定processor
                .writer(writer)//给step绑定writer
                .faultTolerant()
                .retry(Exception.class)   // 重试
                .noRetry(ParseException.class)
                .retryLimit(1)           //每条记录重试一次
                .skip(Exception.class)
                .skipLimit(200)         //一共允许跳过200次异常
//                .taskExecutor(new SimpleAsyncTaskExecutor()) //设置每个Job通过并发方式执行,一般来讲一个Job就让它串行完成的好
//                .throttleLimit(10)        //并发任务数为 10,默认为4
                .build();
    }
 
Example 7
@Bean
SpringBatchFlowRunner mySpringBatchFlowRunner(
		StepBuilderFactory stepBuilderFactory,
		JobBuilderFactory jobBuilderFactory,
		ProjectsToRunFactory projectsToRunFactory, JobLauncher jobLauncher,
		FlowRunnerTaskExecutorSupplier flowRunnerTaskExecutorSupplier,
		ConfigurableApplicationContext context,
		ReleaserProperties releaserProperties, BuildReportHandler reportHandler) {
	return new SpringBatchFlowRunner(stepBuilderFactory, jobBuilderFactory,
			projectsToRunFactory, jobLauncher, flowRunnerTaskExecutorSupplier,
			context, releaserProperties, reportHandler) {
		@Override
		Decision decide(Options options, ReleaserTask task) {
			return Decision.CONTINUE;
		}
	};
}
 
Example 8
SpringBatchFlowRunner(StepBuilderFactory stepBuilderFactory,
		JobBuilderFactory jobBuilderFactory,
		ProjectsToRunFactory projectsToRunFactory, JobLauncher jobLauncher,
		FlowRunnerTaskExecutorSupplier flowRunnerTaskExecutorSupplier,
		ConfigurableApplicationContext context, ReleaserProperties releaserProperties,
		BuildReportHandler reportHandler) {
	this.stepBuilderFactory = stepBuilderFactory;
	this.jobBuilderFactory = jobBuilderFactory;
	this.projectsToRunFactory = projectsToRunFactory;
	this.jobLauncher = jobLauncher;
	this.flowRunnerTaskExecutorSupplier = flowRunnerTaskExecutorSupplier;
	this.stepSkipper = new ConsoleInputStepSkipper(context, reportHandler);
	this.releaserProperties = releaserProperties;
	this.executorService = Executors.newFixedThreadPool(
			this.releaserProperties.getMetaRelease().getReleaseGroupThreadCount());
}
 
Example 9
Source Project: CogStack-Pipeline   Source File: RemoteConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
public Job job(JobBuilderFactory jobs,
               StepBuilderFactory steps,
               Partitioner partitioner,
               @Qualifier("partitionHandler") PartitionHandler partitionHandler,
               JobCompleteNotificationListener jobCompleteNotificationListener,
               @Qualifier("tLJobParametersIncrementer") TLJobParametersIncrementer runIdIncrementer

               ) {
    return jobs.get(jobName)
            .incrementer(runIdIncrementer)
            .listener(jobCompleteNotificationListener)
            .flow(
                    steps
                            .get(jobName + "MasterStep")
                            .partitioner((jobName+"SlaveStep"), partitioner)
                            .partitionHandler(partitionHandler)
                            .build()
            )
            .end()
            .build();

}
 
Example 10
Source Project: CogStack-Pipeline   Source File: LocalConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
public Job job(JobBuilderFactory jobs,
               StepBuilderFactory steps,
               Partitioner partitioner,
               JobCompleteNotificationListener jobCompleteNotificationListener,
               @Qualifier("partitionHandler") PartitionHandler partitionHandler,
               @Qualifier("tLJobParametersIncrementer") TLJobParametersIncrementer runIdIncrementer

) {
    return jobs.get(env.getProperty("job.jobName"))
            .incrementer(runIdIncrementer)
            .listener(jobCompleteNotificationListener)
            .flow(
                    steps
                            .get(jobName + "MasterStep")
                            .partitioner((jobName+"SlaveStep"), partitioner)
                            .partitionHandler(partitionHandler)
                            .build()
            )
            .end()
            .build();

}
 
Example 11
Source Project: Demo   Source File: CsvBatchConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Step step1(StepBuilderFactory stepBuilderFactory, ItemReader<Student> reader, ItemWriter<Student> writer,
        ItemProcessor<Student,Student> processor) {
    return stepBuilderFactory
            .get("step1")
            .<Student, Student>chunk(65000) //批处理每次提交 65000 条数据
            .reader(reader) // 给 step 绑定 reader
            .processor(processor) // 给 step 绑定 processor
            .writer(writer) // 给 step 绑定 writer
            .build();
}
 
Example 12
Source Project: spring-batch-rest   Source File: AdHocScheduler.java    License: Apache License 2.0 5 votes vote down vote up
@Autowired
public AdHocScheduler(JobBuilder jobBuilder, Scheduler scheduler, JobBuilderFactory jobBuilderFactory,
		StepBuilderFactory stepBuilderFactory) {
	this.jobBuilder = jobBuilder;
	this.scheduler = scheduler;
	this.jobBuilderFactory = jobBuilderFactory;
	this.stepBuilderFactory = stepBuilderFactory;
}
 
Example 13
Source Project: spring-batch   Source File: CapitalizeNamesJobConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public Job capitalizeNamesJob(JobBuilderFactory jobBuilders,
    StepBuilderFactory stepBuilders) {
  return jobBuilders.get("capitalizeNamesJob")
      .start(capitalizeNamesStep(stepBuilders))
      .next(deleteFilesStep(stepBuilders)).build();
}
 
Example 14
Source Project: Spring-5.0-Cookbook   Source File: BatchConfig.java    License: MIT License 5 votes vote down vote up
@Bean("step1")
public Step step1(StepBuilderFactory stepBuilderFactory, ItemReader<Employee> reader,
                     ItemProcessor<Employee, Permanent> processor) {
      return stepBuilderFactory.get("step1")
              .<Employee, Permanent>chunk(5)
              .reader(reader)
              .processor(processor)
              .writer(writer())
              .build();
}
 
Example 15
Source Project: Spring-5.0-Cookbook   Source File: BatchConfig.java    License: MIT License 5 votes vote down vote up
@Bean("step2")
public Step step2(StepBuilderFactory stepBuilderFactory, ItemReader<Employee> reader,
                   ItemProcessor<Employee, Permanent> processor) {
      return stepBuilderFactory.get("step2")
              .<Employee, Permanent>chunk(2)
              .reader(reader)
              .processor(processor)
              .writer(xmlWriter())
              .build();
}
 
Example 16
@Bean
@ConditionalOnMissingBean
FlowRunner flowRunner(StepBuilderFactory stepBuilderFactory,
		JobBuilderFactory jobBuilderFactory,
		ProjectsToRunFactory projectsToRunFactory, JobLauncher jobLauncher,
		FlowRunnerTaskExecutorSupplier flowRunnerTaskExecutorSupplier,
		ConfigurableApplicationContext context, ReleaserProperties releaserProperties,
		BuildReportHandler reportHandler) {
	return new SpringBatchFlowRunner(stepBuilderFactory, jobBuilderFactory,
			projectsToRunFactory, jobLauncher, flowRunnerTaskExecutorSupplier,
			context, releaserProperties, reportHandler);
}
 
Example 17
Source Project: CogStack-Pipeline   Source File: JobConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@Qualifier("compositeSlaveStep")
public Step compositeSlaveStep(
                    ItemReader<Document> reader,
        @Qualifier("compositeItemProcessor") ItemProcessor<Document, Document> processor,
        @Qualifier("compositeESandJdbcItemWriter") ItemWriter<Document> writer,
        @Qualifier("slaveTaskExecutor")TaskExecutor taskExecutor,
        @Qualifier("nonFatalExceptionItemProcessorListener")
                            ItemProcessListener nonFatalExceptionItemProcessorListener,
        //@Qualifier("targetDatasourceTransactionManager")PlatformTransactionManager manager,
        StepBuilderFactory stepBuilderFactory
) {
    FaultTolerantStepBuilder stepBuilder = stepBuilderFactory.get("compositeSlaveStep")
            .<Document, Document> chunk(chunkSize)
            .reader(reader)
            .processor(processor)
            .writer(writer)
            .faultTolerant()
            .skipLimit(skipLimit)
            .skip(WebserviceProcessingFailedException.class);
    if (env.acceptsProfiles("jdbc_out_map")) {
      stepBuilder = stepBuilder.skip(InvalidDataAccessApiUsageException.class);
    }
    return stepBuilder.noSkip(Exception.class)
     //       .listener(nonFatalExceptionItemProcessorListener)
            .listener(new SkipListener())
            .taskExecutor(taskExecutor)
            .build();
}
 
Example 18
Source Project: messaging   Source File: BatchConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
Job job(JobBuilderFactory jobBuilderFactory,
 StepBuilderFactory stepBuilderFactory, JdbcTemplate template,
 ItemReader<Contact> fileReader,
 ItemProcessor<Contact, Contact> emailProcessor,
 ItemWriter<Contact> jdbcWriter) {

 Step setup = stepBuilderFactory.get("clean-contact-table")
  .tasklet((contribution, chunkContext) -> {
   template.update("delete from CONTACT");
   return RepeatStatus.FINISHED;
  }).build();

 Step fileToJdbc = stepBuilderFactory.get("file-to-jdbc-fileToJdbc")
  .<Contact, Contact>chunk(5)
  // <1>
  .reader(fileReader).processor(emailProcessor).writer(jdbcWriter)
  .faultTolerant().skip(InvalidEmailException.class)
  // <2>
  .skipPolicy((Throwable t, int skipCount) -> {
   LogFactory.getLog(getClass()).info("skipping ");
   return t.getClass().isAssignableFrom(InvalidEmailException.class);
  }).retry(HttpStatusCodeException.class) // <3>
  .retryLimit(2).build();

 return jobBuilderFactory.get("etl") // <4>
  .start(setup).next(fileToJdbc).build();
}
 
Example 19
@Bean
public Step addressMigrationStep(final StepBuilderFactory stepBuilderFactory,
                                 final ItemStreamReader<BatchTaskAddress> addressReader,
                                 final ItemProcessor<BatchTaskAddress, BatchTaskAddress> addressMigrationProcessor,
                                 final ItemWriter<BatchTaskAddress> addressWriter) throws Exception {
    return stepBuilderFactory.get("addressMigrationStep")
            .<BatchTaskAddress, BatchTaskAddress>chunk(1)
            .reader(addressReader)
            .processor(addressMigrationProcessor)
            .writer(addressWriter)
            .build();
}
 
Example 20
@Bean
public Step deleteFileStep(final Tasklet deleteFileTasklet,
                           final StepBuilderFactory stepBuilderFactory) {
    return stepBuilderFactory
            .get("deleteFileStep")
            .tasklet(deleteFileTasklet)
            .build();
}
 
Example 21
@Bean
public Step addressImportStep(final FlatFileItemReader<BatchTaskAddress> fileItemReader,
                              final ItemWriter<BatchTaskAddress> addressDatabaseWriter,
                              final StepBuilderFactory stepBuilderFactory) {
    return stepBuilderFactory
            .get("addressImportStep")
            .<BatchTaskAddress, BatchTaskAddress>chunk(1)
            .reader(fileItemReader)
            .writer(addressDatabaseWriter)
            .build();
}
 
Example 22
@Bean
public Step addressPrinterStep(final StepBuilderFactory stepBuilderFactory,
                               final ItemStreamReader<Long> addressPrinterReader,
                               final ItemProcessor<Long, Address> addressPrinterProcessor,
                               final ItemWriter<Address> addressPrinterWriter) throws Exception {
    return stepBuilderFactory
            .get("addressPrinterStep")
            .<Long, Address>chunk(1)
            .reader(addressPrinterReader)
            .processor(addressPrinterProcessor)
            .writer(addressPrinterWriter)
            .allowStartIfComplete(Boolean.TRUE)
            .build();
}
 
Example 23
@Bean
public Step addressBatchTaskDeletionStep(final StepBuilderFactory stepBuilderFactory,
                                         final ItemStreamReader<Long> addressBatchTaskDeletionReader,
                                         final ItemWriter<Long> addressBatchTaskDeletionWriter) throws Exception {
    return stepBuilderFactory
            .get("addressBatchTaskDeletionStep")
            .<Long, Long>chunk(1)
            .reader(addressBatchTaskDeletionReader)
            .writer(addressBatchTaskDeletionWriter)
            .allowStartIfComplete(Boolean.TRUE)
            .build();
}
 
Example 24
public SingleStepJobAutoConfiguration(JobBuilderFactory jobBuilderFactory,
		StepBuilderFactory stepBuilderFactory, SingleStepJobProperties properties,
		ApplicationContext context) {

	validateProperties(properties);

	this.jobBuilderFactory = jobBuilderFactory;
	this.stepBuilderFactory = stepBuilderFactory;
	this.properties = properties;
}
 
Example 25
@Before
public void init() {
	this.jobs = new JobBuilderFactory(this.jobRepository);
	this.steps = new StepBuilderFactory(this.jobRepository, this.transactionManager);
	Tasklet tasklet = (contribution, chunkContext) -> RepeatStatus.FINISHED;
	this.step = this.steps.get("step").tasklet(tasklet).build();
	this.job = this.jobs.get("job").start(this.step).build();
	this.runner = new TaskJobLauncherCommandLineRunner(this.jobLauncher,
			this.jobExplorer, this.jobRepository, new TaskBatchProperties());

}
 
Example 26
Source Project: tutorials   Source File: NumberInfoConfig.java    License: MIT License 5 votes vote down vote up
@Bean
@Qualifier("NotificationStep")
public Step notificationStep(StepBuilderFactory sbf) {
    return sbf.get("Notify step")
        .tasklet(new NotifierTasklet())
        .build();
}
 
Example 27
Source Project: tutorials   Source File: NumberInfoConfig.java    License: MIT License 5 votes vote down vote up
public Step numberGeneratorStep(StepBuilderFactory sbf, int[] values, String prepend) {
    return sbf.get("Number generator")
        .<NumberInfo, Integer> chunk(1)
        .reader(new NumberInfoGenerator(values))
        .processor(new NumberInfoClassifier())
        .writer(new PrependingStdoutWriter<>(prepend))
        .build();
}
 
Example 28
Source Project: tutorials   Source File: NumberInfoConfig.java    License: MIT License 5 votes vote down vote up
public Step numberGeneratorStepDecider(StepBuilderFactory sbf, int[] values, String prepend) {
    return sbf.get("Number generator decider")
        .<NumberInfo, Integer> chunk(1)
        .reader(new NumberInfoGenerator(values))
        .processor(new NumberInfoClassifierWithDecider())
        .writer(new PrependingStdoutWriter<>(prepend))
        .build();
}
 
Example 29
Source Project: tutorials   Source File: NumberInfoConfig.java    License: MIT License 5 votes vote down vote up
@Bean
@Qualifier("first_job")
public Job numberGeneratorNonNotifierJob(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory, @Qualifier("NotificationStep") Step notificationStep) {
    int[] nonNotifierData = { -1, -2, -3 };
    Step step = numberGeneratorStep(stepBuilderFactory, nonNotifierData, "First Dataset Processor");
    return jobBuilderFactory.get("Number generator - first dataset")
        .start(step)
        .on(NOTIFY)
        .to(notificationStep)
        .from(step)
        .on("*")
        .stop()
        .end()
        .build();
}
 
Example 30
Source Project: tutorials   Source File: NumberInfoConfig.java    License: MIT License 5 votes vote down vote up
@Bean
@Qualifier("second_job")
public Job numberGeneratorNotifierJob(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory, @Qualifier("NotificationStep") Step notificationStep) {
    int[] billableData = { 11, -2, -3 };
    Step dataProviderStep = numberGeneratorStep(stepBuilderFactory, billableData, "Second Dataset Processor");
    return jobBuilderFactory.get("Number generator - second dataset")
        .start(dataProviderStep)
        .on(NOTIFY)
        .to(notificationStep)
        .end()
        .build();
}