acktsap / spring-batch-plus

Add useful features to spring batch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spring Batch Plus

maven central version build coverage license

Spring Batch Plus provides extension features to Spring Batch.

Features

Kotlin DSL

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

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

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

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(items: List<String>) {
        println(items)
    }
}

// usage
@Bean
fun testJob(
    sampleTasklet: SampleTasklet,
    batch: BatchDsl,
): Job = batch {
    job("testJob") {
        step("testStep") {
            chunk<Int, String>(3) {
                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
0.2.x 4.3.x 1.5 or higher 1.8 or higher
0.1.x 4.3.x 1.5 or higher 1.8 or higher

Download

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

Gradle

Kotlin

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

Java

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

Maven

Kotlin

<!-- need spring batch -->
<dependency>
    <groupId>org.springframework.batch</groupId>
    <artifactId>spring-batch-core</artifactId>
    <version>{springBatchVersion}</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.batch</groupId>
    <artifactId>spring-batch-core</artifactId>
    <version>{springBatchVersion}</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

  • Jdk8 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

License:Apache License 2.0


Languages

Language:Kotlin 82.2%Language:Java 17.8%