20
Introduction to Spray Scala Kansai Beginners 2014-02-08 Spray のご紹介

Spray intro

Embed Size (px)

Citation preview

Page 1: Spray intro

Introduction to SprayScala Kansai Beginners

2014-02-08

Spray のご紹介

Page 2: Spray intro

• 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を使ってます

Page 3: Spray intro
Page 4: Spray intro

• Mostly Ruby on Rails app.

• Internally use a virtualization product.

• Spray app helps the RoR app control the virtualization product.

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

内部で仮想化製品を使用

Sprayアプリで、仮想化製品の制御部分を補助

Page 5: Spray intro

• 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ベース、高速、軽量、モジュラー化されており、テスト可能

Page 6: Spray intro

Integration layer

RoR app Spray app

Virtualization service

Monitoring service

… and more

HTTP HTTP

Virtualization serviceVirtualization

serviceVirtualization service

REST/HTTPによる統合レイヤー

Page 7: Spray intro

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

Page 8: Spray intro

Why recommend Spray?

Spray のお勧めポイント

Especially to beginners

特に初学者に

Page 9: Spray intro

充分なスピードFast enough

Page 10: Spray intro

— from http://spray.io/blog/2013-05-24-benchmarking-spray/

Page 11: Spray intro

— from http://spray.io/blog/2013-05-24-benchmarking-spray/

Page 12: Spray intro

充分な難しさDifficult enough

Page 13: Spray intro

Scala っぽいやり方に慣れる

Learn theway

Page 14: Spray intro

• Actor and Future based concurrency

• case-classes as message protocols

• type safety

• ‘fluent’ internal DSL

Actor と Future をベースにした concurrency

メッセージプロトコルとしてのcaseクラス

型安全性

「流暢な」内部 DSL

Page 15: Spray intro

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 アプリの受託案件で

ちゃんと機能したけど……

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

Page 16: Spray intro

• API based on mutable operations

• conversions between Scala and Java collections

• Scala as just ‘better Java’

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

Scala と Java のコレクション間の変換

Page 17: Spray intro

Let’s try.(demo)

Page 18: Spray intro

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 アクターを定義し、起動した

リクエストの処理を表わすルートを定義した

子アクターを作り、メッセージをやりとりした

Page 19: Spray intro

QA

Page 20: Spray intro

Image Credits

the spray project Xavi Talledarobynmac DrGrounds

École Polytechnique Fédérale de Lausannekzenon nyul ImagineGolf

sdominick bobkeenan matthew_hull