Sunday 3 January 2016

Going Reactive - Part 1

I have been reading the book Reactive Messaging Patterns with the Actor Model, Applications and Integration in Scala and Akka by Vaughn Vernon.

Reactive Applications

Reactive applications are responsive, resilient, elastic, message-driven and capable of producing a real-time feel.

See http://www.reactivemanifesto.org for more details on the four principles.


The Actor Model

An actor is a computational entity that in response to a message it receives can do the following.

  • Send a finite number of messages to other actors
  • Create a finite number of new actors
  • Designate the behaviour to be used for the next message it receives
There is no assumed sequence to these actions and they will be carried out in parallel.

More specifically actors must not share any mutable state with other actors. Actors have individual mailboxes and don't share queues.

When designing reactive systems using the Actor Model, try to anticipate the unexpected. That doesn't mean you can think of every possible situation up front, but you can build resiliency through supervision which will deal with what you cannot know up front.


Akka


Akka implements the Actor Model. Akka Actors give you:

  • Simple and high-level abstractions for concurrency and parallelism.
  • Asynchronous, non-blocking and highly performant event-driven programming model.
  • Very lightweight event-driven processes (several million actors per GB of heap memory). 

At the next part I will be looking at some example reactive applications using Akka.

Friday 1 January 2016

Akka HTTP Client example

I have been experimenting with Akka HTTP. The following is a simple example of making a GET request using Akka HTTP and printing the response.

The build.sbt is found below.
The client is found below.
Happy New Year! :)