Component
Component는 비즈니스 로직을 구현하고 있는 메소드들을 포함하고 있는 타입이다. 배치에서는 스텝들을 구성하기 위해 작성되는 ItemReader, ItemProcessor, ItemWriter, Tasklet과 같은 Interface의 역할은 미리 정의되어 있다. 개발자는 필요한 인터페이스를 구현하여 Component를 개발하여야 한다.
1. ItemReader
배치 스텝에서 처리할 데이터를 DB 또는 파일 등의 리소스에서 획득하여 ItemProcessor나 ItemWriter에 전달하는 역할을 수행한다.
구현 인터페이스
public interface org.springframework.batch.item.ItemReader
구현 메소드 : 처리 대상 데이터를 건 별로 DB 또는 파일에서 읽어오는 역할을 수행
T read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException;
2. ItemProcessor
ItemReader에서 전달 받은 아이템을 업무 요건에 따라 처리/가공하여 ItemWriter에 전달하는 역할을 수행한다.
구현 인터페이스
public interface org.springframework.batch.item.ItemProcessor<I, O>
구현 메소드 : 처리 대상 데이터를 건 별로 업무요건에 따라 처리하는 역할을 수행
O process(I item) throws Exception;
3. ItemWriter
ItemReader혹은 ItemProcessor에서 전달 받은 아이템을 저장 매체인 DB, 파일에 기록하는 역할을 수행한다.
구현 인터페이스
public interface org.springframework.batch.item.ItemWriter<T>
구현 메소드 : 처리 대상 결과 데이터를 커밋 단위 별로 DB 또는 파일에 기록하거나 외부 시스템에 전송하는 역할을 수행
void write(List<? extends T> items) throws Exception;
4. ItemStream
Step 시작 전 DB 혹은 파일 등의 리소스를 사용하기 위한 초기화 및 스텝 완료 후 리소스 자원을 정리, 진행상태 관리가 필요 시 해당 Interface를 수행한다.
구현 인터페이스
public interface org.springframework.batch.item.ItemStream
구현 메소드 : 초기화 처리 - Step이 시작되기전에 프레임워크에서 호출
void open(ExecutionContext executionContext) throws ItemStreamException;
구현 메소드 : 진행 상태 기록 - 구간 별(commit-interval)로 커밋(commit) 시에 프레임워크에서 호출
void update(ExecutionContext executionContext) throws ItemStreamException;
구현 메소드 : 리소스 정리 작업 - Step 완료 후에 프레임워크에서 호출
void close() throws ItemStreamException;