Introduction to Spray
Spray のご紹介

Scala Kansai Beginners
2014-02-08
•

Suguru Hamazaki
濱崎 俊

•

Software Engineer at MEDIA
INDEX, Inc.
MEDIA INDEX株式会社で勤務

•

Experience: 2 years in Scala + 5
months in Spray
Scala歴2年、Spray歴5ヶ月

•

Use Spray as a backend service of
our product, Sova
SovaのバックエンドでSprayを使ってます
•

Mostly Ruby on Rails app.
ほとんどは Ruby on Rails のアプリ

•

Internally use a virtualization product.
内部で仮想化製品を使用

•

Spray app helps the RoR app control the
virtualization product.
Sprayアプリで、仮想化製品の制御部分を補助
•

an open-source toolkit for building REST/HTTPbased integration layers
REST/HTTPによる統合レイヤーを構築するための、オープンソースなツールキット

•

on top of Scala and Akka
Scala と Akka がベース

•

asynchronous, actor-based, fast, lightweight,
modular and testable
非同期、Actorベース、高速、軽量、モジュラー化されており、テスト可能

— from http://spray.io/
Integration layer
REST/HTTPによる統合レイヤー

Virtualization
Virtualization
service
Virtualization
service
Virtualization
service
service
RoR app

Spray app

HTTP

HTTP

Monitoring
service

…
and more
W

at
h

pr
S

is
ay

t:
no

k

wor
me

e fra
n-on
all-i
sole
t an
con
no
ised
stom
cu
tool
no
ing
ffold
ase t
ca
no s
atab men
c d age
ecifi an
o sp ion m
n
late
at
igr
emp
m
fic t
eci
o sp
n
gine
en
Why recommend
Spray?
Spray のお勧めポイント

Especially to
beginners
特に初学者に
Fast enough
充分なスピード
— from http://spray.io/blog/2013-05-24-benchmarking-spray/
— from http://spray.io/blog/2013-05-24-benchmarking-spray/
Difficult enough
充分な難しさ
Learn the
way
Scala っぽいやり方に慣れる
•

Actor and Future based concurrency
Actor と Future をベースにした concurrency

•

case-classes as message protocols
メッセージプロトコルとしてのcaseクラス

•

type safety
型安全性

•

‘fluent’ internal DSL
「流暢な」内部 DSL
A bad decision I made
before
以前こんな失敗を

•

For an XML-RPC application outsourced from a
customer
XML-RPC アプリの受託案件で

•

•

Scala + apache-xmlrpc + servlet for XML-RPC
app

Worked fine, but…
ちゃんと機能したけど……

•

Didn’t learn many things

あまり多くを学ばなかった
•

API based on mutable
operations
mutable な操作をベースにした API

•

conversions between Scala
and Java collections
Scala と Java のコレクション間の変換

•

Scala as just ‘better Java’
try.	
Let’s
(demo)
What we saw through the
demo
•

Created SBT project for spray app development
Spray アプリ開発用に、SBT のプロジェクトを作った

•

Defined an HttpService actor under ActorSystem
and started it
ActorSystem 管理下に HttpService アクターを定義し、起動した

•

Defined a route that represents how requests are
handled
リクエストの処理を表わすルートを定義した

•

Created a child actor and interact with it
子アクターを作り、メッセージをやりとりした
QA
Image Credits

the spray project

robynmac

DrGrounds

Xavi Talleda

kzenon

École Polytechnique
Fédérale de Lausanne

nyul

ImagineGolf

sdominick

bobkeenan

matthew_hull

Spray intro