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

Thanks for flagging this SlideShare!

Oops! An error has occurred.

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

  • 1,036 views
Published

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

Published in Technology , Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,036
On SlideShare
0
From Embeds
0
Number of Embeds
5

Actions

Shares
Downloads
0
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

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