Defining actors

An actor in Akka must extend traits of the same name and implement the receive method:

class Cook extends Actor {    override def receive = {          case _ =>     }}

The type of the receive action is defined as type Receive = PartialFunction[Any, Unit]which closely resembles the abstract definition of an actor model. In Akka, actors can receive any message, and any of the actor's activities are manifested as a change in its state or as a side-effect.

Our defined actor accepts any message and does nothing. This is probably the simplest and laziest actor possible.

In order to make it useful, let's define its behavior and vocabulary.

As we're building an enterprise bakery, our actors will have a single responsibility, which is also a ...

Get Learn Scala Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.