https://docs.spring.io/spring-batch/docs/current/reference/html/index-single.html#spring-batch-intro
Spring Batch - Reference Documentation
If a group of Steps share similar configurations, then it may be helpful to define a "parent" Step from which the concrete Steps may inherit properties. Similar to class inheritance in Java, the "child" Step combines its elements and attributes with the pa
docs.spring.io
Spring batch architecture
JobLauncher : Job을 실행시키는 컴포넌트
Job : 배치작업
JobRepository : Job 실행과 Job, Step 저장
Step : 배치 작업의 단계
ItemReader, ItemProcessor, ItemWriter : 데이터를 읽고 처리하고 쓰는 구성
Spring batch layer
Application Layer
- 사용자 코드와 구성
- 비지니스, 서비스 로직
- Core, Infrastructure를 이용해 배치 기능을 만듬
Batch Core
- 배치 작업을 시작하고 제어하는데 필수적인 클래스 ( Job, Step, JobLuncher )
Infrastructure
- 외부와 상호작용 ( ItemReader, ItemWriter, RetryTemplate )
Job
전체 배치 프로세스를 캡슐화한 도메인
Step의 순서를 정의
JobParameters를 받음
@Bean 으로 선언
jobBuilderFactory에서 이름을 footballJob 이라는 이름으로 정의
start(), next() 안에 있는 친구들은 step의 이름
Step
작업 처리의 단위
Chunk 기반 스텝, Tasklet 기반 스텝 2가지로 나뉨 ( 상단의 Item~ 들이 Chunk 기반의 Step )
Chunk-oriented Processing with Item Processor
chunk 기반으로 하나의 트랜잭션에서 데이터를 처리
commitInterval만큼 데이터를 읽고 트랜젝션 경계 내에서 chunkSize만큼 write
chunkSize : 한 트랜잭션에서 쓸 아이템의 개수
commitInterval : reader가 한번에 읽을 아이템의 개수
보통은 chunkSize와 commitInterval을 맞춰주고 사용하는 것이 좋다
chunk 기반과 tasklet 기반의 step의 코드 차이
tasklet은 내부에 읽기 쓰기 처리 로직을 모두 넣는다
RepeatStatus (반복 상태)를 설정한다 ( RepeatStatus.FINISHIED )
Spring Batch Schema
Spring Batch Meta-Data ERD
Spring Batch Framework가 실행 시 metadata 테이블들을 사용하므로 초기 설정 필요
Spring Batch Framework가 속하는 부분이므로 수정하지 않고 조회만 한다
Job의 이력, 파라미터 등 실행 결과를 조회할 수 있다
배치 결과에 대해서 로그, 별도의 실행 이력을 남기는 경우가 대부분이므로 조회할 일이 많지 않다