liveBook · Manning

Monitoring

As explained in Akka in Action, Second Edition

Failure monitoring is the observation of actors for termination or failure signals so that recovery actions can be taken.

Monitoring observes actors so that messages, termination, or failure behavior can be detected and recovery actions can follow. In Akka, it serves both automated actor tests and fault-tolerant actor arrangements. section 4.3.1 section 5.5.1

Use monitoring to:

  • Place a test probe in front of an actor so messages sent to the monitored behavior can be intercepted and checked. section 4.3.1
  • Verify message cascades when one actor forwards work to another actor or to a probe. section 4.3.1
  • Monitor actors in a processing chain and respawn them when unexpected stopping would otherwise leave references sending messages to deadLetters. section 5.5.1

Intercepting a message

Create a probe, wrap the behavior with Behaviors.monitor(probe.ref, behaviorUnderTest), spawn the monitored behavior, send it "checking", and assert probe.expectMessage("checking"). The probe observes the message while the actor remains the object under test. section 4.3.1

class AsyncForwardSpec ...
  ...
 
  "a monitor" must {
 
    "intercept the messages" in {
 
      val probe = createTestProbe[String]
      val behaviorUnderTest = Behaviors.receiveMessage[String] { _ =>
        Behaviors.ignore
      }
      val behaviorMonitored = Behaviors.monitor(probe.ref, behaviorUnderTest)                             #1
      val actor = testkit.spawn(behaviorMonitored)
 
      actor ! "checking"
      probe.expectMessage("checking")
 
    }
  }
  ...
}

Shows the complete monitor test structure, including the probe, monitored behavior, spawned actor, sent message, and expected observation. section 4.3.1

How Akka in Action, Second Edition covers it

How deep it goes
Explains probe interception and monitored-actor respawning, while leaving detailed signal-handling design to supervision.
Examples
Uses SimplifiedManager forwarding tests and a logging pipeline containing a file watcher, log processor, and database writer.
What it assumes
Assumes actors, behaviors, ActorRefs, and asynchronous messaging, while demonstrating probe creation and monitoring directly.
What you can do after
Apply monitoring through Behaviors.monitor and probes, or design actor chains that detect stopped components and respawn them.
How it connects
Connects monitoring with actors, ActorRef, probes, supervision, actor lifecycle signals, restart strategies, and deadLetters.

Also explained in

Compare how 40 books explain monitoring →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Akka in Action, Second Edition. The section links point to the parts of the book it draws on.