Share
Embed
Finagle Coding Dojo
David Denton
October 10, 2017
Transcript
7 slides
-
Finagle Dojo Scala meet up / 4th October 2017 David
Denton / Andrea Birotti @daviddenton/finagle-dojo -
• 2013 Whitepaper from Marius Eriksen @ Twitter Server as
a Function • Defined 2 major concepts: • Service represents System Boundaries • Filter used to apply I/O transformation and stateful effects • Protocol agnostic RPC system • In production @ Twitter • Fault tolerance baked in • Scala + Netty -
Concept: Future “Represents the result of an Asynchronous operation.” val
result: String = Await.result( Future.value("content") .map(v => v + v) .flatMap(v => Future(v)) .handle { case _: Exception => "failed" } ) • 2 end states: Value and Exception • Manipulate with: map() / flatMap() / handle() / rescue() • Can get the result with Await - but never block!! -
Concept: Service “It turns an Request into an (eventual) Response”
Service: Request => Future[Response] ie. it’s a function! val service = new Service[Request, Response] { override def apply(request: Request): Future[Response] = { val response = Response(Status.Ok) response.content = request.content Future(response) } } -
Concept: Filter “Provides pre and post processing on an HTTP
operation” Filter[ReqIn, RespIn, ReqOut, RespOut] = [ReqIn, Service[ReqOut, RespOut]] => Future[RespIn] ie. it’s a function! val addType = new Filter[Request, Response, Request, Response] { override def apply(request: Request, service: Service[Request, Response]) = { service(request).map(resp => { resp.headerMap("Content-type") = "application/json" resp }) } } Filters compose with other Filters/Services using andThen() -
Let’s get started! • clone: https://github.com/daviddenton/finagle-dojo.git • project is using
(sbt 1.0.1) - adjust before import! • use the readmes at the root & in each step folder • finagle docs @ https://twitter.github.io/finagle/guide/ -
more? • Join us for the October LSUG meet up
on October 23rd where we’ll be presenting Fintrospect - a type safe routing layer built on top of Finagle, and how it changed our CD and testing practices. fintrospect.io @daviddenton/fintrospect web: www.fintrospect.io