Skip to content

naver/spring-batch-plus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Batch Plus

maven central version build coverage license

Spring Batch Plus provides extension features to Spring Batch.

Features

Kotlin DSL

@Bean
fun testJob(batch: BatchDsl): Job = batch {
    job("testJob") {
        step("jobStep1") {
            jobBean("subJob1")
        }
        step("jobStep2") {
            jobBean("subJob2")
        }
    }
}

@Bean
fun subJob1(batch: BatchDsl, transactionManager: PlatformTransactionManager): Job = batch {
    job("subJob1") {
        step("testStep1") {
            tasklet({ _, _ -> RepeatStatus.FINISHED }, transactionManager)
        }
    }
}

@Bean
fun subJob2(batch: BatchDsl, transactionManager: PlatformTransactionManager): Job = batch {
    job("subJob2") {
        step("testStep2") {
            tasklet({ _, _ -> RepeatStatus.FINISHED }, transactionManager)
        }
    }
}

Single class reader-processor-writer

  • ItemStreamFluxReaderProcessorWriter
  • ItemStreamIterableReaderProcessorWriter
  • ItemStreamIterableReaderProcessorWriter
  • ItemStreamSimpleReaderProcessorWriter
// single class
@Component
@StepScope
class SampleTasklet : ItemStreamFluxReaderProcessorWriter<Int, String> {
    private var count = 0

    override fun readFlux(executionContext: ExecutionContext): Flux<out Int> {
        return Flux.generate { sink ->
            if (count < 20) {
                sink.next(count)
                ++count
            } else {
                sink.complete()
            }
        }
    }

    override fun process(item: Int): String? {
        return "'$item'"
    }

    override fun write(chunk: Chunk<String>) {
        println(chunk.items)
    }
}

// usage
@Bean
fun testJob(
    sampleTasklet: SampleTasklet,
    batch: BatchDsl,
): Job = batch {
    job("testJob") {
        step("testStep") {
            chunk<Int, String>(3, ResourcelessTransactionManager()) {
                reader(sampleTasklet.asItemStreamReader())
                processor(sampleTasklet.asItemProcessor())
                writer(sampleTasklet.asItemStreamWriter())
            }
        }
    }
}

Other Useful Classes

  • ClearRunIdIncrementer
  • DeleteMetadataJob

Compatibility

We've tested following versions only. Other versions may not work.

Batch Plus (Latest) Batch Boot Starter Kotlin Java Status Samples
1.1.x (1.1.0) 5.1.x 3.2.x ~ 3.2.x 1.5 or higher 17 or higher Maintained Samples
1.0.x (1.0.1) 5.0.x 3.0.x ~ 3.1.x 1.5 or higher 17 or higher Maintained Samples
0.3.x (0.3.1) 4.3.x 2.4.x ~ 2.7.x 1.5 or higher 1.8 or higher Maintained Samples
0.2.x (0.2.0) 4.3.x 2.4.x ~ 2.7.x 1.5 or higher 1.8 or higher Freezed Samples
0.1.x (0.1.0) 4.3.x 2.4.x ~ 2.7.x 1.5 or higher 1.8 or higher Freezed Samples

Download

Since it provides extension features to spring batch, need to used with spring batch.

Gradle

Kotlin

implementation("org.springframework.boot:spring-boot-starter-batch:${springBootVersion}") // need spring batch
implementation("com.navercorp.spring:spring-boot-starter-batch-plus-kotlin:${springBatchPlusVersion}")

Java

implementation("org.springframework.boot:spring-boot-starter-batch:${springBootVersion}") // need spring batch
implementation("com.navercorp.spring:spring-boot-starter-batch-plus:${springBatchPlusVersion}")

Maven

Kotlin

<!-- need spring batch -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-batch</artifactId>
    <version>{springBootVersion}</version>
</dependency>
<dependency>
    <groupId>com.navercorp.spring</groupId>
    <artifactId>spring-boot-starter-batch-plus-kotlin</artifactId>
    <version>{springBatchPlusVersion}</version>
</dependency>

Java

<!-- need spring batch -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-batch</artifactId>
    <version>{springBootVersion}</version>
</dependency>
<dependency>
    <groupId>com.navercorp.spring</groupId>
    <artifactId>spring-boot-starter-batch-plus</artifactId>
    <version>{springBatchPlusVersion}</version>
</dependency>

User Guide

Build from source

Prerequisites

  • Jdk 17 or higher
  • Kotlin 1.5 or higher

Build

  • Clean: ./gradlew clean
  • Check: ./gradlew check
    • Check coverage: ./gradlew koverMergedVerify
    • Make a merged coverage report: ./gradlew koverMergedReport
      • Coverage report will be generated in ${projectRoot]/build/kover/html/index.html
  • Assemble: ./gradlew build
  • Install to local: ./gradlew install
  • Publish: ./gradlew publish --no-parallel

License

   Copyright (c) 2022-present NAVER Corp.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.