Top Banner
Reactive SOA with Finagle
12

Finagle Lightning Talk JPR 2014

Apr 14, 2017

Download

Software

Chris Phelps
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Finagle Lightning Talk JPR 2014

Reactive SOA with Finagle

Page 2: Finagle Lightning Talk JPR 2014

Finagle Protocol agnostic RPC framework From Twitter Async and non-blocking built on Netty

and Futures Scala and Java APIs

Page 3: Finagle Lightning Talk JPR 2014

Services and Filters Servicetrait Service[Req, Rep] extends (Req => Future[Rep])

Filterabstract class Filter[-ReqIn, +RepOut, +ReqOut, -RepIn] extends ((ReqIn, Service[ReqOut, RepIn]) => Future[RepOut])

Compositionval retryWithTimeout = retryFilter andThen timeoutFilter andThen service

Page 4: Finagle Lightning Talk JPR 2014

Rest + RPC

Page 5: Finagle Lightning Talk JPR 2014

Combining services Services return Futures Service calls may need prior results Don’t wait for completion Futures have callbacks

onSuccess onFailure

Page 6: Finagle Lightning Talk JPR 2014

Nested Callbacks

Page 7: Finagle Lightning Talk JPR 2014

Future Composition

Page 8: Finagle Lightning Talk JPR 2014

CombinatorsFuture[A] map { A => B } : Future[B]

Future[A] flatMap { A => Future[B] } : Future[B]

Page 9: Finagle Lightning Talk JPR 2014

Example

Page 10: Finagle Lightning Talk JPR 2014

User Serviceclass UserServiceImpl extends UserRpc.FutureIface { def getUser() = { val user = User(Some("Chris”),

Some("[email protected]")) Future.value(user) }}

Page 11: Finagle Lightning Talk JPR 2014

Client (flatMap)val userfuture = userclient.getUser()val contentfuture = tenantclient.getTenant() flatMap { tenant => contentclient.getContent(tenant) } flatMap { content => userfuture flatMap { user => personalizeclient .personalizeContent(content, user) } }

Page 12: Finagle Lightning Talk JPR 2014

Client (for-comprehension)val newcontentfuture = for { user <- userclient.getUser() tenant <- tenantclient.getTenant() content <- contentclient.getContent(tenant) personalized <- personalizeclient.personalizeContent(content, user)} yield personalized

contentfuture onSuccess { message => println("received content response: " + message.customtext.get) }