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

The following examples show how to use org.springframework.batch.core.configuration.annotation.StepBuilderFactory. 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: BatchConfiguration.java    From building-microservices with 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
Source File: RemoteConfiguration.java    From CogStack-Pipeline with Apache License 2.0 7 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 #3
Source File: LocalConfiguration.java    From CogStack-Pipeline with 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 #4
Source File: AbstractSpringAcceptanceTests.java    From spring-cloud-release-tools with Apache License 2.0 6 votes vote down vote up
@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 #5
Source File: SpringBatchFlowRunner.java    From spring-cloud-release-tools with Apache License 2.0 6 votes vote down vote up
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 #6
Source File: AppConfig.java    From SpringBootBucket with 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
Source File: LogConfig.java    From SpringBootBucket with 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 #8
Source File: CantonConfig.java    From SpringBootBucket with 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 #9
Source File: BudgetVtollConfig.java    From SpringBootBucket with 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 #10
Source File: BatchConfiguration.java    From Software-Architecture-with-Spring-5.0 with MIT License 6 votes vote down vote up
@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 #11
Source File: BatchConfiguration.java    From messaging with 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 #12
Source File: JobConfiguration.java    From CogStack-Pipeline with 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 #13
Source File: AddressPrinterJobConfiguration.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@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 #14
Source File: BatchConfiguration.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
@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 #15
Source File: BatchConfig.java    From Spring-5.0-Cookbook with 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
Source File: BatchConfig.java    From Spring-5.0-Cookbook with 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 #17
Source File: AddressMigrationJobConfiguration.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@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 #18
Source File: AddressImportJobConfiguration.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@Bean
public Step deleteFileStep(final Tasklet deleteFileTasklet,
                           final StepBuilderFactory stepBuilderFactory) {
    return stepBuilderFactory
            .get("deleteFileStep")
            .tasklet(deleteFileTasklet)
            .build();
}
 
Example #19
Source File: AddressImportJobConfiguration.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@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 #20
Source File: AddressPrinterJobConfiguration.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@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 #21
Source File: SingleStepJobAutoConfiguration.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
public SingleStepJobAutoConfiguration(JobBuilderFactory jobBuilderFactory,
		StepBuilderFactory stepBuilderFactory, SingleStepJobProperties properties,
		ApplicationContext context) {

	validateProperties(properties);

	this.jobBuilderFactory = jobBuilderFactory;
	this.stepBuilderFactory = stepBuilderFactory;
	this.properties = properties;
}
 
Example #22
Source File: TaskJobLauncherCommandLineRunnerCoreTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@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 #23
Source File: NumberInfoConfig.java    From tutorials with 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 #24
Source File: NumberInfoConfig.java    From tutorials with 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 #25
Source File: NumberInfoConfig.java    From tutorials with 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 #26
Source File: NumberInfoConfig.java    From tutorials with 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 #27
Source File: NumberInfoConfig.java    From tutorials with 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();
}
 
Example #28
Source File: CapitalizeNamesJobConfig.java    From spring-batch with 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 #29
Source File: NumberInfoConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
@Qualifier("third_job")
@Primary
public Job numberGeneratorNotifierJobWithDecider(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory, @Qualifier("NotificationStep") Step notificationStep) {
    int[] billableData = { 11, -2, -3 };
    Step dataProviderStep = numberGeneratorStepDecider(stepBuilderFactory, billableData, "Third Dataset Processor");
    return jobBuilderFactory.get("Number generator - third dataset")
        .start(dataProviderStep)
        .next(new NumberInfoDecider())
        .on(NOTIFY)
        .to(notificationStep)
        .end()
        .build();
}
 
Example #30
Source File: AdHocScheduler.java    From spring-batch-rest with 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;
}