spray intro
TRANSCRIPT
Introduction to SprayScala Kansai Beginners
2014-02-08
Spray のご紹介
• Suguru Hamazaki
• Software Engineer at MEDIA INDEX, Inc.
• Experience: 2 years in Scala + 5 months in Spray
• Use Spray as a backend service of our product, Sova
濱崎 俊
MEDIA INDEX株式会社で勤務
Scala歴2年、Spray歴5ヶ月
SovaのバックエンドでSprayを使ってます
• Mostly Ruby on Rails app.
• Internally use a virtualization product.
• Spray app helps the RoR app control the virtualization product.
ほとんどは Ruby on Rails のアプリ
内部で仮想化製品を使用
Sprayアプリで、仮想化製品の制御部分を補助
• an open-source toolkit for building REST/HTTP-based integration layers
• on top of Scala and Akka
• asynchronous, actor-based, fast, lightweight, modular and testable
— from http://spray.io/
REST/HTTPによる統合レイヤーを構築するための、オープンソースなツールキット
Scala と Akka がベース
非同期、Actorベース、高速、軽量、モジュラー化されており、テスト可能
Integration layer
RoR app Spray app
Virtualization service
Monitoring service
… and more
HTTP HTTP
Virtualization serviceVirtualization
serviceVirtualization service
REST/HTTPによる統合レイヤー
not an all-in-one framework
What Spray is not:
no customised console
no scaffolding tool
no specific database
migration management
no specific template
engine
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
Scala っぽいやり方に慣れる
Learn theway
• Actor and Future based concurrency
• case-classes as message protocols
• type safety
• ‘fluent’ internal DSL
Actor と Future をベースにした concurrency
メッセージプロトコルとしてのcaseクラス
型安全性
「流暢な」内部 DSL
A bad decision I made before
• For an XML-RPC application outsourced from a customer
• Scala + apache-xmlrpc + servlet for XML-RPC app
• Worked fine, but…
• Didn’t learn many things
以前こんな失敗を
XML-RPC アプリの受託案件で
ちゃんと機能したけど……
あまり多くを学ばなかった
• API based on mutable operations
• conversions between Scala and Java collections
• Scala as just ‘better Java’
mutable な操作をベースにした API
Scala と Java のコレクション間の変換
Let’s try.(demo)
What we saw through the demo
• Created SBT project for spray app development
• Defined an HttpService actor under ActorSystem and started it
• Defined a route that represents how requests are handled
• Created a child actor and interact with it
Spray アプリ開発用に、SBT のプロジェクトを作った
ActorSystem 管理下に HttpService アクターを定義し、起動した
リクエストの処理を表わすルートを定義した
子アクターを作り、メッセージをやりとりした
QA
Image Credits
the spray project Xavi Talledarobynmac DrGrounds
École Polytechnique Fédérale de Lausannekzenon nyul ImagineGolf
sdominick bobkeenan matthew_hull