Defining an actor

To define an actor, the class needs to extend the actor and implement the required abstract method for handling messages.


public class MyActor extends UntypedActor {
  public void onReceive(Object message) throws Exception {


class MyActor extends Actor {
  def receive = {

An Actor class can also have non-default constructors. So any data that needs to be passed at the time of the object creation can be passed to the Actor object. In Scala, the receive block is actually a partial function, which allows the usage of pattern matching syntax.

Get Akka Essentials now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.