ちょっと Qiita 使う用事ができたので、練習も兼ねて。
Qiita には、はじめて全体公開で投稿してみる。
Spring XD 公式マニュアルのままだけど、試してみたのでメモ。
https://spring.io/guides/gs/spring-xd/
環境
以下のとおり。
$ sw_vers -productName
Mac OS X
$ sw_vers -productVersion
10.10.3
$ brew --version
0.9.5 (git revision 692f; last commit 2015-11-16)
インストール
これもマニュアルのとおり、Brew で簡単に入った。
$ brew tap pivotal/tap && brew install springxd
==> Tapping pivotal/tap
Cloning into '/usr/local/Library/Taps/pivotal/homebrew-tap'...
remote: Counting objects: 16, done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 16 (delta 2), reused 5 (delta 0), pack-reused 0
Unpacking objects: 100% (16/16), done.
Checking connectivity... done.
Tapped 10 formulae (50 files, 208K)
==> Installing springxd from pivotal/homebrew-tap
==> Downloading http://repo.spring.io/libs-release-local/org/springframework/xd/spring-xd/1.3.0.RELEASE/spring-xd-1.3.0.RELE
######################################################################## 100.0%
==> Caveats
Usage:
To start XD single node (runs in foreground):
xd-singlenode
To start XD admin and container separately (all run in foreground):
brew update && brew install redis
brew install zookeeper
redis-server
hsqldb-server
zkServer start
xd-admin
xd-container
Start XD Shell:
xd-shell
Create your first stream by typing following in xd shell:
xd:> stream create --definition "time | log" --name ticktock
Documentation:
http://docs.spring.io/spring-xd/docs/1.3.0.RELEASE/reference/html/
==> Summary
🍺 /usr/local/Cellar/springxd/1.3.0.RELEASE: 1060 files, 524M, built in 2.5 minutes
Spring XD の起動
引き続きマニュアルのとおり、起動してみる。
マニュアルには $XD_INSTALL_DIR/xd/bin/xd-singlenode
とあったが、インストール時にパスが通っていたため、xd-singlenode
のみで問題なかった。
$ xd-singlenode
_____ __ _______
/ ___| (-) \ \ / / _ \
\ `--. _ __ _ __ _ _ __ __ _ \ V /| | | |
`--. \ '_ \| '__| | '_ \ / _` | / ^ \| | | |
/\__/ / |_) | | | | | | | (_| | / / \ \ |/ /
\____/| .__/|_| |_|_| |_|\__, | \/ \/___/
| | __/ |
|_| |___/
1.3.0.RELEASE eXtreme Data
Started : SingleNodeApplication
Documentation: https://github.com/spring-projects/spring-xd/wiki
...
Spring Boot でもそうだけど、最近バナー出すの流行ってるのかな。
起動できた。
Spring XD の動作確認
別のターミナルを開いて、今度は XD Shell を起動。
$ xd-shell
_____ __ _______
/ ___| (-) \ \ / / _ \
\ `--. _ __ _ __ _ _ __ __ _ \ V /| | | |
`--. \ '_ \| '__| | '_ \ / _` | / ^ \| | | |
/\__/ / |_) | | | | | | | (_| | / / \ \ |/ /
\____/| .__/|_| |_|_| |_|\__, | \/ \/___/
| | __/ |
|_| |___/
eXtreme Data
1.3.0.RELEASE | Admin Server Target: http://localhost:9393
Welcome to the Spring XD shell. For assistance hit TAB or type "help".
xd:>
またバナー。
シングルサーバー起動の時点で、XD を管理するためのサーバーが起動しており、起動したシェルがどのサーバーをターゲットにしているかという情報として、Admin Server Target: http://localhost:9393
というのが表示される。
管理サーバーには GUI もついており、http://localhost:9393/admin-ui/ からアクセスできる。
ここでは、起動したコンテナ、デプロイされたストリーム、バッチジョブ、他の確認と管理ができる。
マニュアルに戻って、引き続きストリームの作成とデプロイを試してみる。
xd:> stream create --name twittersearchjava --definition "twittersearch --consumerKey=afes2uqo6JAuFljdJFhqA --consumerSecret=0top8crpmd1MXGEbbgzAwVJSAODMcbeAbhwHXLnsg --query='java' | file" --deploy
どうやら、Twitter から java
のキーワードを検索した結果をファイルに吐き続けるもののようだ。
tail
で出力を確認できる。
$ tail -f /tmp/xd/output/twittersearchjava.out
{"contributors":null,"coordinates":null,"created_at":"Mon Nov 30 03:59:05 +0000 2015","entities":{"hashtags":[{"indices":[53,64],"text":"CommonCore"},{"indices":[79,88],"text":"StopESEA"},{"indices":[92,107],"text":"StopCommonCore"},{"indices":[108,114],"text":"PJNET"}],"symbols":[],"urls":[{"display_url":"PatriotJournalist.com/StopESEAAction…","expanded_url":"http://PatriotJournalist.com/StopESEAActionPix.php?c=101","indices":[115,138],"url":"https://t.co/9j79Dy7qaP"}],"user_mentions":[{"id":185456717,"id_str":"185456717","indices":[3,14],"name":"Laura Oosse","screen_name":"4todayonly"},{"id":27943436,"id_str":"27943436","indices":
...
管理サーバーでも登録が確認できる。

最後に、あんまり放っておくと、ファイルが肥大化してしまうので止めておく。
アンデプロイも管理サーバーからラクラク。

アンデプロイリクエストから、3秒以内ならキャンセルもできる。
いろいろ使い道ありそうなので、もうちょっと触ってみようと思う。