REACTIVE WITH PLAY AND AKKA 
Markus Jura
ABOUT ME 
Consultant 
@Typesafe 
Living in Hamburg 
Co-Founder of 
testmunk 
3 years Scala, 10 years Java background 
Follow @markusjura Follow @markusjura 233 followers
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())); 
}
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()))); 
}
WEBSOCKETS OVERVIEW
WEBSOCKETS CLIENT CODE 
ws = new WebSocket("ws://url/echo") 
ws.onmessage = (event) -> 
alert(event.data) 
ws.onopen = () -> 
ws.send("Echo") 
CoffeeScript
WEBSOCKETS SERVER CODE 
public static WebSocket<JsonNode> echo() { 
return WebSocket.whenReady((in, out) -> { 
in.onMessage(out::write); 
in.onClose(() -> Logger.debug("Connection closed")); 
}); 
} 
Play Controller
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)
REACTIVE STOCKS ARCHITECTURE
Demo
THANK YOU 
Slide Deck on 
Reactive Stocks 
Github 
Activator Template 
Follow @markusjura Follow @markusjura 233 followers

Introduction to Reactive with Play and Akka - Markus Jura

  • 1.
    REACTIVE WITH PLAYAND AKKA Markus Jura
  • 2.
    ABOUT ME Consultant @Typesafe Living in Hamburg Co-Founder of testmunk 3 years Scala, 10 years Java background Follow @markusjura Follow @markusjura 233 followers
  • 3.
  • 4.
  • 5.
    ROUTES VERB PATHCONTROLLER_METHOD GET / controllers.Application.index() GET /foo controllers.Application.foo() Declarative, type-safe URL Mapping
  • 6.
    CONTROLLERS public staticResult index() { return ok("Hello World!"); }
  • 7.
    ASYNCHRONOUS REQUEST importplay.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)); }
  • 8.
    HTTP REQUEST publicstatic Promise<Result> getPage() { final Promise<WSResponse> promise = WS.url("http://google.com").get(); return promise.map(response -> ok(response.getBody())); }
  • 9.
    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()))); }
  • 10.
  • 11.
    WEBSOCKETS CLIENT CODE ws = new WebSocket("ws://url/echo") ws.onmessage = (event) -> alert(event.data) ws.onopen = () -> ws.send("Echo") CoffeeScript
  • 12.
    WEBSOCKETS SERVER CODE public static WebSocket<JsonNode> echo() { return WebSocket.whenReady((in, out) -> { in.onMessage(out::write); in.onClose(() -> Logger.debug("Connection closed")); }); } Play Controller
  • 13.
    Single unified programmingmodel for Simpler concurrency Simpler distribution Simpler fault tolerance
  • 14.
    SIMPLER CONCURRENCY Actorslet us write code in a single-threaded illusion No locks, synchronized or other primitives needed
  • 15.
    SIMPLER DISTRIBUTION Everythingin Akka is distributed by default Akka goes from remote to local by optimization
  • 16.
    SIMPLER FAULT TOLERANCE Akka decouples communication from failure handling: Supervisors handle failure Callers need not care (they can't anyway)
  • 17.
  • 18.
  • 19.
    THANK YOU SlideDeck on Reactive Stocks Github Activator Template Follow @markusjura Follow @markusjura 233 followers