About Me – Thank you



About Me – Thank you

0 0


reactive-akka-play


On Github markusjura / reactive-akka-play

Reactive with Play and Akka

Markus Jura

About Me

Reactive Apps

reactivemanifesto.org

  • Productivity
  • Scalable
  • Modern web & mobile

Routes

VERB    PATH         CONTROLLER_METHOD

GET     /            controllers.Application.index()
GET     /foo         controllers.Application.foo()

Declarative, type-safe URL Mapping

Controllers

public static Result index() {
  return ok("Hello World!");
}

Asynchronous Request

import play.libs.F.*;

private static Integer calc() {
    return (5134 * 5789) / 349;
}

public static Promise<Result> basicPromise() { 
  Promise<Integer> promise = Promise.promise(() -> calc()); 
  return promise.map(i -> ok("Result is: " + i));
}

HTTP Request

public static Promise<Result> getPage() { 
  final Promise<WSResponse> promise = 
    WS.url("http://google.com").get();
  return promise.map(response -> ok(response.getBody()));
}

- Fully async and non-blocking - Client to Server, Server to Service

Concurrent HTTP Requests

public static Promise<Result> composition() { 
  final Promise<WSResponse> googlePromise = 
    WS.url("http://google.com").get();
  final Promise<WSResponse> twitterPromise = 
    WS.url("http://twitter.com").get();

  return googlePromise.flatMap(google ->
    twitterPromise.map(twitter ->
      ok(google.getBody() + twitter.getBody())));
}

- Three requests, two in parallel (depending on thread availability) - All async & non-blocking

  • Single unified programming model for
    • Simpler concurrency
    • Simpler distribution
    • Simpler fault tolerance

Simpler Concurrency

  • Actors let us write code in a single-threaded illusion
  • No locks, synchronized or other primitives needed

Simpler Distribution

  • Everything in Akka is distributed by default
  • Akka goes from remote to local by optimization

Simpler Fault Tolerance

Akka decouples communication from failure handling:

  • Supervisors handle failure
  • Callers need not care (they can't anyway)

Demo

Reactive Stocks Architecture

Thank you