Java Code Examples for org.springframework.batch.core.Step

The following examples show how to use org.springframework.batch.core.Step. 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: 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 2
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 3
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 4
@Override
public Step getObject() throws Exception {
	TaskLauncherTasklet taskLauncherTasklet = new TaskLauncherTasklet(
			this.taskOperations, taskConfigurer.getTaskExplorer(),
			this.composedTaskProperties, this.taskName, taskProperties);

	taskLauncherTasklet.setArguments(this.arguments);
	taskLauncherTasklet.setProperties(this.taskSpecificProps);

	String stepName = this.taskName;

	return this.steps.get(stepName)
			.tasklet(taskLauncherTasklet)
			.transactionAttribute(getTransactionAttribute())
			.listener(this.composedTaskStepExecutionListener)
			.build();
}
 
Example 5
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 6
@Bean
public Step step1(JdbcBatchItemWriter<Voltage> writer) {
    return stepBuilderFactory.get("step1")
            .<Voltage, Voltage> chunk(10)
            .reader(reader())
            .processor(processor())
            .writer(writer)
            .build();
}
 
Example 7
Source Project: Demo   Source File: CsvBatchConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Job importJob(JobBuilderFactory jobs, Step s1) {
    return jobs.get("importJob")
            .incrementer(new RunIdIncrementer())
            .flow(s1) //为 job 指定 step
            .end()
            .listener(csvJobListener()) //绑定监听器 csvJobListener
            .build();
}
 
Example 8
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 9
Source Project: spring-graalvm-native   Source File: BatchConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Step step1() {
	return this.stepBuilderFactory.get("step1")
			.tasklet(new Tasklet() {
				@Override
				public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
					System.out.println(">> This was run in a Spring Batch app!");

					return RepeatStatus.FINISHED;
				}
			}).build();
}
 
Example 10
Source Project: seed   Source File: StepService0006.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Step step0006(){
    return stepBuilderFactory.get("step0006")
            .listener(this.settleJobListeners)
            .<Person, Person>chunk(10)
            .reader(this.reader())
            .processor(this.processor())
            .writer(this.writer())
            .build();
}
 
Example 11
Source Project: spring-graalvm-native   Source File: BatchConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Step step1(ItemReader<CustomerCredit> itemReader,
		ItemProcessor<CustomerCredit, CustomerCredit> itemProcessor,
		ItemWriter<CustomerCredit> itemWriter) {
	return this.stepBuilderFactory.get("step1")
			.<CustomerCredit, CustomerCredit>chunk(2)
			.reader(itemReader)
			.processor(itemProcessor)
			.writer(itemWriter)
			.build();
}
 
Example 12
Source Project: spring-cloud   Source File: JpaPagingStep.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Step stepInJpaPagingWithJdbcBatchItemWriter() {
    return stepBuilderFactory
            .get("stepInJpaPagingWithJdbcBatchItemWriter")
            .<User, People>chunk(10)
            .reader(jpaPagingItemReader)
            .processor(userPeopleItemProcessor)
            .writer(jdbcBatchItemWriter)
            .build();
}
 
Example 13
Source Project: spring-cloud   Source File: JpaPagingStep.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Step stepInJpaPagingWithRepositoryItemWriter() {
    return stepBuilderFactory
            .get("stepInJpaPagingWithRepositoryItemWriter")
            .<User, People>chunk(10)
            .reader(jpaPagingItemReader)
            .processor(userPeopleItemProcessor)
            .writer(repositoryItemWriter)
            .build();
}
 
Example 14
Source Project: spring-cloud   Source File: FlatFileBatchStep.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Step repositoryItemWriterStep() {
    return stepBuilderFactory
            .get("repositoryItemWriterStep")
            .<User, People>chunk(10)
            .reader(flatFileItemReader)
            .processor(userPeopleItemProcessor)
            .writer(repositoryItemWriter)
            .build();
}
 
Example 15
Source Project: spring-cloud   Source File: RepositoryStep.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Step stepWithRepositoryReaderAndWriter() {
    return stepBuilderFactory.get("stepWithRepositoryReaderAndWriter")
            .<User, People>chunk(10)
            .reader(repositoryItemReaderWithParams)
            .processor(userPeopleItemProcessor)
            .writer(repositoryItemWriter)
            .build();
}
 
Example 16
Source Project: spring-cloud   Source File: RepositoryStep.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Step stepWithRepository() {
    return stepBuilderFactory.get("stepWithRepository")
            .<User, People>chunk(10)
            .reader(repositoryItemReader)
            .processor(userPeopleItemProcessor)
            .writer(repositoryItemWriter)
            .build();
}
 
Example 17
@Bean
public Job javaChampionsLoader(JobBuilderFactory jobs, @Qualifier(STEP_PROCESS_CSV_FILE) Step step) {
    return jobs.get(JAVA_CHAMPIONS_LOADER_JOB)
            .flow(step)
            .end()
            .build();
}
 
Example 18
@Bean
public Job importPayRollJob(JobCompletionPayRollListener listener, Step step1) {
    return jobBuilderFactory.get("importPayRollJob")
            .incrementer(new RunIdIncrementer())
            .listener(listener)
            .flow(step1)
            .end()
            .build();
}
 
Example 19
@Bean
public Step step1(JdbcBatchItemWriter<PayrollTo> writer) {
    return stepBuilderFactory.get("step1")
            .<PayrollTo, PayrollTo> chunk(10)
            .reader(reader())
            .processor(processor())
            .writer(writer)
            .build();
}
 
Example 20
@Bean
public Step ourBatchStep() {
	return stepBuilderFactory.get("stepPackPub1")
			.tasklet(new Tasklet() {
				public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
					return null;
				}
			})
			.build();
}
 
Example 21
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 22
@Bean
public Step step(ItemReader<PatientRecord> itemReader,
                 Function<PatientRecord, PatientEntity> processor,
                 JpaItemWriter<PatientEntity> writer) throws Exception {
    return this.stepBuilderFactory
        .get(Constants.STEP_NAME)
        .<PatientRecord, PatientEntity>chunk(2)
        .reader(itemReader)
        .processor(processor)
        .writer(writer)
        .build();
}
 
Example 23
Source Project: seed   Source File: StepService0004.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Step step0004(){
    return stepBuilderFactory.get("step0004")
            .listener(this.settleJobListeners)
            .<Person, Person>chunk(1)
            .reader(this.reader())
            .processor(this.processor())
            .writer(this.writer())
            .build();
}
 
Example 24
Source Project: SpringBootBucket   Source File: LogConfig.java    License: MIT License 5 votes vote down vote up
/**
 * Job定义,我们要实际执行的任务,包含一个或多个Step
 *
 * @param jobBuilderFactory
 * @param s1
 * @return
 */
@Bean(name = "zlogJob")
public Job zlogJob(JobBuilderFactory jobBuilderFactory, @Qualifier("logStep1") Step s1) {
    return jobBuilderFactory.get("zlogJob")
            .incrementer(new RunIdIncrementer())
            .flow(s1)//为Job指定Step
            .end()
            .listener(new MyJobListener())//绑定监听器csvJobListener
            .build();
}
 
Example 25
Source Project: SpringBootBucket   Source File: AppConfig.java    License: MIT License 5 votes vote down vote up
/**
 * Job定义,我们要实际执行的任务,包含一个或多个Step
 *
 * @param jobBuilderFactory
 * @param s1
 * @return
 */
@Bean(name = "zappJob")
public Job zappJob(JobBuilderFactory jobBuilderFactory, @Qualifier("zappStep1") Step s1) {
    return jobBuilderFactory.get("zappJob")
            .incrementer(new RunIdIncrementer())
            .flow(s1)//为Job指定Step
            .end()
            .listener(new MyJobListener())//绑定监听器csvJobListener
            .build();
}
 
Example 26
Source Project: spring-batch-rest   Source File: PersonJobConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
Job personJob(@Qualifier("personStep") Step personStep) {
    return JobBuilder.registerJob(jobRegistry, jobs.get(JOB_NAME)
            .incrementer(new RunIdIncrementer())
            .start(personStep)
            .build());
}
 
Example 27
Source Project: spring-batch-rest   Source File: PersonJobConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
Step personStep(@Qualifier("personProcessor") ItemProcessor personProcessor) {
    return steps.get("personStep")
            .allowStartIfComplete(true)
            .<Person, Person>chunk(3)
            .reader(personReader())
            .processor(personProcessor)
            .writer(personWriter())
            .build();
}
 
Example 28
Source Project: spring-batch-rest   Source File: PersonJobConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
Job personJob(@Qualifier("personStep") Step personStep) {
    return adHocScheduler.schedule(PersonJobConfig.JOB_NAME, jobs.get(JOB_NAME)
            .incrementer(new RunIdIncrementer())
            .flow(personStep)
            .end()
            .build(), "0 0 12 * * ?");
}
 
Example 29
Source Project: spring-batch-rest   Source File: PersonJobConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
Step personStep(@Qualifier("personProcessor") ItemProcessor personProcessor) {
    return steps.get("personStep")
            .allowStartIfComplete(true)
            .<Person, Person>chunk(3)
            .reader(personReader())
            .processor(personProcessor)
            .writer(personWriter())
            .build();
}
 
Example 30
Source Project: Spring-5.0-Cookbook   Source File: BatchConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public Job importUserJob(JobBuilderFactory jobs, Step step1, Step step2, JobExecutionListener listener) {
       return jobs.get("importUserJob")
               .incrementer(new RunIdIncrementer())
               .listener(listener)
               .flow(step1)
               .next(step2)
               .end()
               .build();
 }