10. What is Spray?
spray is an open-source toolkit for
building REST/HTTP-based
integration layers on top of Scala
and Akka. Being asynchronous,
actor-based, fast, lightweight,
modular and testable it's a great
way to connect your Scala
applications to the world.
19. Application Layers
Spray Router
Handle raw level http request & response
Bidding Business Logic
External Resources"
Fetch bidding candidates from data stores
20. Application Layers
Global Dispatcher
Spray Router
Handle raw level http request & response
Bidding Business Logic
External Resources"
Fetch bidding candidates from data stores
21. Application Layers
Spray Router
Handle raw level http request & response
Bidding Business Logic
External Resources"
Router Dispatcher
Service Dispatcher
Fetch bidding candidates from data stores
Repository Dispatcher
22. Implementation
trait Router {
implicit val ec = RouterDispatcher
def handle: Future[BidResponse]
}
trait Service {
implicit val ec = ServiceDispatcher
def bidding: Future[Bidder]
}
trait Repository {
implicit val ec = RepositoryDispatcher
def candidates: Future[List[Candidate]]
}
23. How to test those
Future[T] things
• Specs2 - Matcher[Future[T]]
bidding must beEqual(expected).await
bidding must beEqual(expected).await
(
retries = 2,
timeout = 100.millis
)
26. Type class &
Implicit
object Service {
implicit def fs = new Service[Future] {
implicit val ec = ServiceDispatcher
val M = Monad[Future]
}
implicit def ids = new Service[Id] {
val M = Monad[Id]
}
} // type Id[+A] = A
27. Test Again
val s = Service.ids
s.bidding must beEqual(expected)
28. M[_] for Monad
• Monad is a structure that
represents computations defined
as sequences of steps
• Don’t dive into “Monad” here!
40. Summary
• Future Directive on Spray
• Abstract Future
(Type class & Implicit)
• Akka master/worker pattern
• Monitoring Akka with Kamon
41. Best Practices?
• https://github.com/alexandru/
scala-best-practices
• So many “MUST NOT, SHOULD NOT”
• In my opinion, Trial and Error to
find right patterns
42. We are Hiring!
• 一緒に働く仲間を募集しています!
Scalaに興味のある方はぜひ!
adtech_scala@cyberagent.co.jp