An Introduction to Akka
Mikołaj Koziarkiewicz
Akka - what is it? 1/2
a platform,
"for building highly concurrent, distributed, and resilient message-driven
applications on the JVM."[1],
based on the actor model.
Akka - what is it? 2/2
platform has a lot of specialized extensions
all based on the actor core
goal of the presentation:
explain the core
Actor model - what is it?
actor: unit of computation
actors build actor systems
quite "old" (1973).[2]
Anatomy of an Akka Actor - intro 1/2
class MyActor extends Actor {
def receive = {
case Something => //...
}
}
Anatomy of an Akka Actor - intro 2/2
My first Akka Actor™
class HaiActor extends Actor {
def receive: Receive = {
case target: ActorRef => target ! "Hello!"
case "Hello!" => sender ! "OHAI"
case "OHAI" => println(s"$self: got OHAI from
$sender")
}
}
Where:
type Receive = PartialFunction[Any, Unit]
My first Akka Actor™ - example
Anatomy of an Akka Actor - hierarchy
Akka actor model - lifecycle & hierarchy
Purpose:
division of labor
supervision:
each actor has lifecycle
special hooks - preStart, preRestart, postStop
allow for e.g. self-init
"parent" controls how it reacts to failure
Hierarchy - example
Akka - guarantees
an actor processes one message at a time,
a message will be delivered at most 1 times,
messages are ordered by sender
Guarantee takeaways
don’t pass mutable state,
use services to ensure send:
contex.scheduler
persistence
Testing
Akka Testkit
Features:
can run special 1-thread dispatcher
asserts for getting msgs
TestProbe
Remoting
Simple remoting:
e.g. "akka.tcp://remote@freund.de:1337
/user/actorName"
remote creation as well
Talking to actor system
Custom:
ask pattern
ask(actoRef, request)(timeout): Future
Many others (also builtin)
Summary
Akka - actor model on the JVM
alternative way to handle
concurrency
distribution
declared guarantees
make reasoning easier
THANK YOU!
The End
Doc link:
http://doc.akka.io/docs/akka/current/scala.html
Bibliography
http://akka.io , retrieved 2015-04-20
https://en.wikipedia.org/wiki/History_of_the_Actor_model , retrieved
2015-04-12

An Introduction to Akka

  • 1.
    An Introduction toAkka Mikołaj Koziarkiewicz
  • 2.
    Akka - whatis it? 1/2 a platform, "for building highly concurrent, distributed, and resilient message-driven applications on the JVM."[1], based on the actor model.
  • 3.
    Akka - whatis it? 2/2 platform has a lot of specialized extensions all based on the actor core goal of the presentation: explain the core
  • 4.
    Actor model -what is it? actor: unit of computation actors build actor systems quite "old" (1973).[2]
  • 5.
    Anatomy of anAkka Actor - intro 1/2 class MyActor extends Actor { def receive = { case Something => //... } }
  • 6.
    Anatomy of anAkka Actor - intro 2/2
  • 7.
    My first AkkaActor™ class HaiActor extends Actor { def receive: Receive = { case target: ActorRef => target ! "Hello!" case "Hello!" => sender ! "OHAI" case "OHAI" => println(s"$self: got OHAI from $sender") } } Where: type Receive = PartialFunction[Any, Unit]
  • 8.
    My first AkkaActor™ - example
  • 9.
    Anatomy of anAkka Actor - hierarchy
  • 10.
    Akka actor model- lifecycle & hierarchy Purpose: division of labor supervision: each actor has lifecycle special hooks - preStart, preRestart, postStop allow for e.g. self-init "parent" controls how it reacts to failure
  • 11.
  • 12.
    Akka - guarantees anactor processes one message at a time, a message will be delivered at most 1 times, messages are ordered by sender
  • 13.
    Guarantee takeaways don’t passmutable state, use services to ensure send: contex.scheduler persistence
  • 14.
    Testing Akka Testkit Features: can runspecial 1-thread dispatcher asserts for getting msgs TestProbe
  • 15.
  • 16.
    Talking to actorsystem Custom: ask pattern ask(actoRef, request)(timeout): Future Many others (also builtin)
  • 17.
    Summary Akka - actormodel on the JVM alternative way to handle concurrency distribution declared guarantees make reasoning easier
  • 18.
    THANK YOU! The End Doclink: http://doc.akka.io/docs/akka/current/scala.html Bibliography http://akka.io , retrieved 2015-04-20 https://en.wikipedia.org/wiki/History_of_the_Actor_model , retrieved 2015-04-12