Save 37% off PRO during our Black Friday Sale! »

Finagle Coding Dojo

Finagle Coding Dojo

Ed250c56ee7dac44d90e5fdf712314f2?s=128

David Denton

October 10, 2017
Tweet

Transcript

  1. Finagle Dojo Scala meet up / 4th October 2017 David

    Denton / Andrea Birotti @daviddenton/finagle-dojo
  2. • 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
  3. 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!!
  4. 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) } }
  5. 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()
  6. 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/
  7. 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