2. What is Akka?
A toolkit that provides:
simple concurrency
resiliency
elasticity
high performance
3. What is an actor?
Receive and send messages
Define behavior for
next message
Create other actors
4. The Actor model of computation
processing - behavior
storage - state model
I/O - messages
5. Key things to understand
messages processed sequentially
multiple actors can be working at the same time
actors are not threads
an actor can block (but should minimize it)
no shared state
6. A very simple actor
class MyActor extends Actor with ActorLogging {
def receive = {
case msg ⇒
log.info(“Received: {}”, msg)
}
}
7. Creating actors in an actor system
Everything begins here:
val system = ActorSystem("example")
val myActor = system.actorOf(Props[MyActor],
name = “myActor”)
myActor ! “a boring message”
8. Messages
Can be any object
Should be immutable
Should be serializable
Ideally define a protocol for communication
9. Protocol
“a system of rules that explain the
correct conduct and procedures to
be followed in formal situations”
— Merriam-Webster
10. Message protocols
Define the interaction between actors
Specify clear boundaries
Encode success and failure clearly
20. Extras
● Supervisors
○ provide exception handling
○ “let it crash”
○ orthogonal to actor behavior
● Location transparency
○ abstracts the idea of “where” an actor lives
21. Extras
● Mailboxes
● Routing
○ e.g., round-robin, smallest mailbox, etc.
● Dispatching
○ essentially how to allocate thread resources