Anatomy of a Reactive Application

13
Anatomy of a Reactive Application Reactive Programming Enthusiasts Denver Meet-up Kick-Off Mark Wilson

description

Presentation for the kick-off meeting for the meetup: "Reactive Programming Enthusiasts Denver". This talks about concurrency, non-blocking, scala, futures, akka, play framework, and other concepts of reactive programming.

Transcript of Anatomy of a Reactive Application

Page 1: Anatomy of a Reactive Application

Anatomy of a Reactive Application

Reactive Programming Enthusiasts Denver Meet-up Kick-Off

Mark Wilson

Page 2: Anatomy of a Reactive Application

Demo Application

Scala

Akka

Play!

Intended to Illustrate some concepts of Reactive Programming, Introduce:

but the demo is mostly about Non-Blocking

Page 3: Anatomy of a Reactive Application

Amdahl’s Law“… Therefore it is important that the entire solution is

asynchronous and non-blocking. ” - Reactive Manifesto

Page 4: Anatomy of a Reactive Application

FuturesA 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 }

Page 5: Anatomy of a Reactive Application

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

Page 6: Anatomy of a Reactive Application

ActorFrom the book “Akka Concurrency”

by Derek Wyatt

Page 7: Anatomy of a Reactive Application

Web Tier (Play)

Stateless: horizontally scalable

Aims to allow concurrency throughout the application

Fits with REST/ powerful javascript

An open source web application framework, written in Scala and Java, which follows the model–view–

controller architectural pattern.

Page 8: Anatomy of a Reactive Application

AkkaUsing 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

Page 9: Anatomy of a Reactive Application

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

Page 10: Anatomy of a Reactive Application

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.

Supervision/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)

Page 11: Anatomy of a Reactive Application

“It is better to fail in originality than to succeed in imitation.”

–Herman Melville

Page 12: Anatomy of a Reactive Application

Up Next?!

March 2014

Page 13: Anatomy of a Reactive Application

RPED Chunk-O-Thon OneCollective 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!

March 2014