Finagle - an intro to rpc & a sync programming in jvm

1,680 views

Published on

This is an novice level presentation to get started with writing
protocols using Finagle in Scala language

Published in: Technology, Education
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,680
On SlideShare
0
From Embeds
0
Number of Embeds
120
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Finagle - an intro to rpc & a sync programming in jvm

  1. 1. Finagle - An Intro to RPC &Async programming in JVMPrasanna Kumar.Sprasanna.sathyanarayanan@csscorp.comTwitter @prasonscala
  2. 2. AgendaWhy RPC & Async programming is Interesting ?Lets know about "Future" & "Promise "Finagle !!!! - Writing Protocol HandlersCode - Lets get in to ActionUse Cases - Where could I use FinagleQ&A
  3. 3. Why RPC & Asyncprogramming ?I know my infrastructureI wanna provide an platformIsolated computation with callable APIsDont call me let me call u !!!RPC + Async gives steroids for your server apps
  4. 4. Lets know aboutFutureThe fundmental abstraction of Async Programming (Fingale aswell :-) )A Future is computation which has not yetperformed, i.e it is supposed to happen !!!
  5. 5. FinagleWriting Protocol HandlersClient and Server are just serviceDefine Server / Client in terms of service
  6. 6. Exposing a Service - (ServerSide)// implement a serviceval service = new Service[HttpRequest, HttpResponse] {def apply(req: HttpRequest) = {Future(new DefaultHttpResponse(HttpVersion.HTTP_1_1,HttpResponseStatus.OK))}}// configure the serviceServerBuilder().codec(Http()).bindTo(new InetSocketAddress(10000)).name("chutti-server").build(service)
  7. 7. Consuming with Clientval client = ClientBuilder().codec(Http()).hosts("10.10.27.14:10000").hostConnectionLimit(1).build()val req = new DefaultHttpRequest(HttpVersion.HTTP_1_1,HttpMethod.GET, "/")val fut = client(req)fut onSuccess (msg => {println(msg)})
  8. 8. Putting it allobject ChuttiServer {private lazy val globalResponse = (req: HttpRequest) => {val resp = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK)val htmlRes = "welcome finagle session !!!!".getBytes()resp.setContent(ChannelBuffers.copiedBuffer(htmlRes))Future.value(resp)}def start(): Unit = {// implement a serviceval service = new Service[HttpRequest, HttpResponse] {def apply(req: HttpRequest) = {req.getUri() match {case "/" => globalResponse(req)case _ => Future(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND))} } }val fil = new ChuttiServerFilter[HttpRequest, HttpResponse](Duration.fromMilliseconds(100), new JavaTimer)val svc = fil andThen fil andThen service// configure the serviceServerBuilder().codec(Http()).bindTo(new InetSocketAddress(10000)).name("localhost").build(svc)}}// Filter definitionclass ChuttiServerFilter[HttpRequest, HttpResponse](timeout: Duration, timer: Timer)extends Filter[HttpRequest, HttpResponse, HttpRequest, HttpResponse]
  9. 9. {def apply(request: HttpRequest, service: Service[HttpRequest, HttpResponse]): Future[HttpResponse] = {println("req passed thru")service(request)}}
  10. 10. Putting it all (Contd.)object ChuttiClient {def main(args: Array[String]) {val client = ClientBuilder().codec(Http()).hosts("10.10.27.14:10000").hostConnectionLimit(1).build()val req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/")val fut = client(req)fut onSuccess (msg => {println(msg)})}}
  11. 11. Use Cases - Where could I useFinagle
  12. 12. Q&A
  13. 13. The ENDThanksReveal.jsHTML5 CSS3Sublime Text Editor

×