Skip to content

junminpark817/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

// single class
@Component
@StepScope
class SampleTasklet : ItemStreamReaderProcessorWriter<Int, String> {
    private var count = 0

    override fun readFlux(executionContext: ExecutionContext): Flux<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.

Spring Batch Plus Version Spring Batch Version Kotlin Version Java Version Samples
1.0.x 5.0.x 1.5 or higher 17 or higher Samples
0.3.x 4.3.x 1.5 or higher 1.8 or higher Samples
0.2.x 4.3.x 1.5 or higher 1.8 or higher Samples
0.1.x 4.3.x 1.5 or higher 1.8 or higher 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.

About

Add useful features to spring batch

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 79.2%
  • Java 20.8%