Slide 1

Slide 1 text

Finagle Dojo Scala meet up / 4th October 2017 David Denton / Andrea Birotti @daviddenton/finagle-dojo

Slide 2

Slide 2 text

• 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

Slide 3

Slide 3 text

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!!

Slide 4

Slide 4 text

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) } }

Slide 5

Slide 5 text

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()

Slide 6

Slide 6 text

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/

Slide 7

Slide 7 text

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