Anatomy of a
Reactive Application
Reactive Programming Enthusiasts Denver
Meet-up Kick-Off
Mark Wilson
Demo Application
Intended to Illustrate some concepts of Reactive
Programming, Introduce:

Scala
Akka
Play!
but the demo is mostly about Non-Blocking
Amdahl’s Law
“… Therefore it is important that the entire solution is
asynchronous and non-blocking. ” - Reactive Manifesto
Futures
A Future is an object holding a value which
may become available at some point.
!
•

A Future is either completed or not completed

•

A completed Future is either:
•

successful (value)

•

or failed (exception)

!
!

import scala.concurrent.ExecutionContext.Implicits.global	
import scala.concurrent._	
val fs: Future[String] = Future { “a” + “b” }	
fs.onComplete {	
case Success(x) => println(x)	
case Failure(e) => throw e	
}
The Fish Store
1. Play GET and POST, non-blocking
2. Akka Actors processing a delivery
Start from the start a most simple web page
Actor
From the book “Akka Concurrency”
by Derek Wyatt
Web Tier (Play)
An open source web application framework, written in
Scala and Java, which follows the model–view–
controller architectural pattern.

Stateless: horizontally scalable
Aims to allow concurrency throughout
the application
Fits with REST/ powerful javascript
Akka
Using the Actor Model we raise the abstraction level and
provide a better platform to build correct, concurrent, and
scalable applications. - akka docs

From the
book “Akka
Concurrency”
by Derek
Wyatt
pipeTo
import akka.pattern.pipe	

!
val future: Future[Any] = someFunctionReturningFuture()	
future pipeTo sender // sends to sender as Future[Any]	

!
// is roughly equivalent to	

!
val mysender = sender // final def sender(): ActorRef	
future.onComplete {	
case Success(x) => mysender ! x	
case Failure(e) => mysender ! akka.actor.Status.Failure(e)	
}	

!
// if sender doesn't handle Failure(e) it is logged as unhandled
Akka More..
Configuration
Akka Test Kit
Akka Extensions
Akka Traits { Stash, ActorLogging }
TypedActor
Akka Events { EventBus, EventStream } - Pub/sub behavior
Akka Scheduler - sending a message to an actor on a schedule.
Super vision/Fault Tolerance { Resume, Restart, Stop, Escalate }
Data Flows - special lib for writing futures: flow { “hi” } onComplete println
Pipeline - sequential processing within an actor
Remote Actors - utilizing actors on remote machines (or clustered machines)
“It is better to fail in originality
than to succeed in imitation.”

–Herman Melville
Up Next?
!

March 2014
RPED Chunk-O-Thon One
March 2014

Collective 3 minute presentations
Open participation
Topics span Reactive Applications
Examples:
Working examples / Shared learning exercise
Well formed problem/question for the group
Weird, funny or unexpected behavior
Realtime UI tricks
Other interesting stuff you come up with
Submissions must be available 1 week prior to meeting
There will be prizes!

Anatomy of a Reactive Application

  • 1.
    Anatomy of a ReactiveApplication Reactive Programming Enthusiasts Denver Meet-up Kick-Off Mark Wilson
  • 2.
    Demo Application Intended toIllustrate some concepts of Reactive Programming, Introduce: Scala Akka Play! but the demo is mostly about Non-Blocking
  • 3.
    Amdahl’s Law “… Thereforeit is important that the entire solution is asynchronous and non-blocking. ” - Reactive Manifesto
  • 4.
    Futures A Future isan object holding a value which may become available at some point. ! • A Future is either completed or not completed • A completed Future is either: • successful (value) • or failed (exception) ! ! import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent._ val fs: Future[String] = Future { “a” + “b” } fs.onComplete { case Success(x) => println(x) case Failure(e) => throw e }
  • 5.
    The Fish Store 1.Play GET and POST, non-blocking 2. Akka Actors processing a delivery Start from the start a most simple web page
  • 6.
    Actor From the book“Akka Concurrency” by Derek Wyatt
  • 7.
    Web Tier (Play) Anopen source web application framework, written in Scala and Java, which follows the model–view– controller architectural pattern. Stateless: horizontally scalable Aims to allow concurrency throughout the application Fits with REST/ powerful javascript
  • 8.
    Akka Using the ActorModel we raise the abstraction level and provide a better platform to build correct, concurrent, and scalable applications. - akka docs From the book “Akka Concurrency” by Derek Wyatt
  • 9.
    pipeTo import akka.pattern.pipe ! val future:Future[Any] = someFunctionReturningFuture() future pipeTo sender // sends to sender as Future[Any] ! // is roughly equivalent to ! val mysender = sender // final def sender(): ActorRef future.onComplete { case Success(x) => mysender ! x case Failure(e) => mysender ! akka.actor.Status.Failure(e) } ! // if sender doesn't handle Failure(e) it is logged as unhandled
  • 10.
    Akka More.. Configuration Akka TestKit Akka Extensions Akka Traits { Stash, ActorLogging } TypedActor Akka Events { EventBus, EventStream } - Pub/sub behavior Akka Scheduler - sending a message to an actor on a schedule. Super vision/Fault Tolerance { Resume, Restart, Stop, Escalate } Data Flows - special lib for writing futures: flow { “hi” } onComplete println Pipeline - sequential processing within an actor Remote Actors - utilizing actors on remote machines (or clustered machines)
  • 11.
    “It is betterto fail in originality than to succeed in imitation.” –Herman Melville
  • 12.
  • 13.
    RPED Chunk-O-Thon One March2014 Collective 3 minute presentations Open participation Topics span Reactive Applications Examples: Working examples / Shared learning exercise Well formed problem/question for the group Weird, funny or unexpected behavior Realtime UI tricks Other interesting stuff you come up with Submissions must be available 1 week prior to meeting There will be prizes!