• Save
Finagle - an intro to rpc & a sync programming in jvm
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

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

on

  • 1,224 views

This is an novice level presentation to get started with writing

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

Statistics

Views

Total Views
1,224
Views on SlideShare
1,182
Embed Views
42

Actions

Likes
1
Downloads
0
Comments
0

5 Embeds 42

http://prassee.com 14
http://assets.txmblr.com 11
http://blog.prassee.me 9
https://assets.txmblr.com 5
http://prasonscala.tumblr.com 3

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

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

  • 1. Finagle - An Intro to RPC &Async programming in JVMPrasanna Kumar.Sprasanna.sathyanarayanan@csscorp.comTwitter @prasonscala
  • 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. 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. 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. FinagleWriting Protocol HandlersClient and Server are just serviceDefine Server / Client in terms of service
  • 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. 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. 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. {def apply(request: HttpRequest, service: Service[HttpRequest, HttpResponse]): Future[HttpResponse] = {println("req passed thru")service(request)}}
  • 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. Use Cases - Where could I useFinagle
  • 12. Q&A
  • 13. The ENDThanksReveal.jsHTML5 CSS3Sublime Text Editor