욱'S 노트

Spring XD - Job Module 개발하기 본문

Programming/Spring XD

Spring XD - Job Module 개발하기

devsun 2015. 2. 5. 16:25

소개


앞에서 현재 XD에서는 4가지 타입의 모듈(source, sink, processor, job)을 지원한다고 했다. 이제 job 모듈을 개발해보자.


간단한 작업 개발하기


사실상 Spring XD에서 job 모듈을 개발한다는 것은 Spring Batch를 기반으로 한다. 일반적인 배치작업을 개발하기를 원한다면 Spring Batch를 참조하기 바란다.


먼저 배치작업을 하나 정의해보자. 그냥 간단한 tasklet하나를 다음과 같이 지정하였다.

설정 파일의 이름은 job-hello.xml으로 하자. 잘 살펴보면 일반 스프링 배치와 차이가 있다. 그것은 별도의 jobRepository의 설정이 필요없다는 것이다. 기본적으로 Spring XD에서 jobRepository를 관리하므로 여기서는 설정을 할 필요가 없다.


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch="http://www.springframework.org/schema/batch"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd">

<batch:job id="helloJob">
<batch:step id="step01">
<batch:tasklet ref="helloTasklet"/>
</batch:step>
</batch:job>

<bean id="helloTasklet" class="net.daum.datahub.test.HelloTasklet"/>
</beans>


Tasklet를 다음과 같이 작성하자.

public class HelloTasklet implements Tasklet {
@Override
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {

System.out.println("Hello XD First Bacth !!!");

return RepeatStatus.FINISHED;
}
}


단순하게 메시지만 콘솔로 출력하는 예제이므로 이미 개발은 끝났다.


테스트하기


일단 Spring XD에서 작업을 구동해보기 위해 배포를 해야 한다. 일단 실행 클래스를 jar 파일로 만들자.

$XD_HOME/xd/modules/job 밑에 job-hello란 디렉토리를 만들고 다음과 같은 구조로 배포하자.


$XD_HOME/xd/modules/job/job-hello 

/config/job-hello.xml

/ lib/job-hello.jar 


Xd-shell 콘솔로 가서 모듈을 조회해보자. 해당 모듈 디렉토리에 빈설정 파일을 자동으로 인식하여 등록이 된다.

job-hello가 등록된 것을 확인할 수 있다.





다음과 같이 배포를 하고 실행을 시키면 된다.



XD쪽 로그를 보면 정상적으로 콘솔에 출력이 발생한다.



결론


개발은 Spring Batch나 Spring Hadoop을 아는 사람이면 쉽게 할 수 있을듯 하다. 오히려 특정한 배포 구조를 맞추는 것이 오히려 관건일듯도 하다.

1.1.0-SNAPSHOT에서는 maven-plugin 등의 feature가 추가되고 있는 듯 하다. Spring Hadoop의 작업으로 테스트를 수행해보고 싶었으나, 레퍼런스 매뉴얼에도 걍 Spring Hadoop을 참고하라고만 나온다. 쩝~



'Programming > Spring XD' 카테고리의 다른 글

Spring XD - Modules  (0) 2015.03.04
Spring XD - Streams  (0) 2015.03.03
Spring XD - Batch Jobs  (0) 2015.02.02
Spring XD - 아키텍처  (0) 2015.01.30
Spring XD - DSL  (0) 2015.01.30
Comments