반응형
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- coalesce
- Spring Open Feign
- grafana
- jmeter
- spring boot redis
- JPA
- docker compose mysql
- Selenium
- docker
- argo cd
- vue.js
- cassandra
- docker-compose
- KAFKA
- Redis Sentinel
- mybatis
- WebLogic
- weblogic 10
- ChannelPipeline
- Airflow
- redis
- netflix oss
- Docker Compose
- MySQL
- spring cloud
- QueryDSL
- RabbitMQ
- Hibernate
- Netty
- spring boot
Archives
- Today
- Total
IT.FARMER
Spring batch 기본 흐름 (tasklet, next flow) 본문
반응형
2020/05/26 - [Spring/Spring Batch] - Spring Batch 특징
2020/05/26 - [Spring/Spring Batch] - Spring batch 기본 흐름 (tasklet, next flow)
2020/05/26 - [Spring/Spring Batch] - Spring Batch 분기/decide
2020/05/26 - [Spring/Spring Batch] - Spring Batch JobParameter
2020/05/26 - [Spring/Spring Batch] - Spring Batch chunk 지향 방식
chunk로 처리해야하는게 능사는 아니다, Step by Step 간단한 프로세스 호출로 구성해야 하는경우는 어떻게 해야 할가 ? 간단한 배치 작업을 위해 스프링배치는 TaskletStep 을 제공한다.
단계에 따른 진행 흐름은 Start로 시작 되어 Next로 이어준다.(chunk 방식도 동일)
@Bean
public Job job() {
return this.jobBuilderFactory.get("job")
.start(stepA())
.next(stepB())
.next(stepC())
.build();
}
1. Tasklet 예제
1.1 MethodInvoking을 통한 호출처리
@Bean
public Step step1() {
return this.stepBuilderFactory.get("step1")
.tasklet(myTasklet())
.build();
}
@Bean
public MethodInvokingTaskletAdapter myTasklet() {
MethodInvokingTaskletAdapter adapter = new MethodInvokingTaskletAdapter();
adapter.setTargetObject(fooDao());
adapter.setTargetMethod("updateFoo");
return adapter;
}
1.2. Tasklet 을 상속한 구현 처리
public class FileDeletingTasklet implements Tasklet, InitializingBean {
private Resource directory;
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext) throws Exception {
File dir = directory.getFile();
Assert.state(dir.isDirectory());
File[] files = dir.listFiles();
for (int i = 0; i < files.length; i++) {
boolean deleted = files[i].delete();
if (!deleted) {
throw new UnexpectedJobExecutionException("Could not delete file " +
files[i].getPath());
}
}
return RepeatStatus.FINISHED;
}
public void setDirectoryResource(Resource directory) {
this.directory = directory;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(directory, "directory must be set");
}
}
@Bean
public Job taskletJob() {
return this.jobBuilderFactory.get("taskletJob")
.start(deleteFilesInDir())
.build();
}
@Bean
public Step deleteFilesInDir() {
return this.stepBuilderFactory.get("deleteFilesInDir")
.tasklet(fileDeletingTasklet())
.build();
}
@Bean
public FileDeletingTasklet fileDeletingTasklet() {
FileDeletingTasklet tasklet = new FileDeletingTasklet();
tasklet.setDirectoryResource(new FileSystemResource("target/test-outputs/test-dir"));
return tasklet;
}
반응형
'Spring > Spring Batch' 카테고리의 다른 글
Spring Batch chunk 지향 방식 (0) | 2020.05.26 |
---|---|
Spring Batch JobParameter (0) | 2020.05.26 |
Spring Batch 분기/decide (0) | 2020.05.26 |
Spring Batch 특징 (0) | 2020.05.26 |