wget http://repo.spring.io/release/org/springframework/xd/spring-xd/1.0.1.RELEASE/spring-xd-1.0.1.RELEASE-dist.zip
unzip spring-xd-1.0.1.RELEASE-dist.zip
cd spring-xd-1.0.1.RELEASE/
이하 모든 경로는 위의 마지막 디렉토리를 기준으로 함.
쓰고 싶은 DB의 JDBC드라이버를 다운로드해서 xd/lib 폴더에 복사. 여기서는 H2 DB를 사용함.
cd xd/lib
wget http://central.maven.org/maven2/com/h2database/h2/1.4.181/h2-1.4.181.jar
참고로 MySql과 Postgres, H2DB의 jar파일은 XD에서 참조할 수 있는 위치에 이미 포함되어 있음.
jdbc.properties을 수정함
vi xd/config/modules/sink/jdbc/jdbc.properties
드라이버클래스, JDBC URL등을 원하는 DB로 변경
driverClassName=org.h2.Driver
url=jdbc:h2:~/apps/h2db;AUTO_SERVER=TRUE
username=sa
password=sa
Spring-XD shell실행
./shell/bin/xd-shell
8181번 포트로 들어오는 JSON body를 바로 JDBC로 입력하는 Stream을 생성함
stream create --name http-to-jdbc --definition "http --port=8181 | jdbc --tableName=person --columns=name,address --initializeDatabase=true" --deploy
Spring XD Shell에서 아래와 같이 실행하거나
http post --target http://localhost:8181 --data "{\"name\":\"Kim\",\"address\":\"Seoul\"}"
OS Shell에서 curl을 이용해도 됨.
curl -XPOST 'http://localhost:8181/' -d '{"name":"benelog","address":"Seoul"}'
JDBC URL로 DB 접속. H2 Console을 이용할 수도 있음. ( https://github.com/benelog/web-db-console/ 참고)