liveBook · Manning

Event

As explained in Akka in Action, Second Edition

An event is a stored record of a state-changing outcome generated by a persistent actor after processing a command.

An event records something that happened. In a persistent actor, it is the accepted output of handling a command: the actor validates the intended change, generates an event, and appends it to a journal instead of replacing a single stored state value. The journal preserves the actor’s complete history. section 9.2

Figure 9.5 From command to a stored event
CH09_F05_Abraham2.

Follow the transition from an incoming command, through validation, to an event stored as a journal entry. section 9.2

Events also act as asynchronous notifications. A Conversation actor can publish that it added a message without knowing which components care. Subscribers such as mentions handling can react later, and connected browsers can receive a direct notification rather than repeatedly polling. section 1.5.2 section 1.5.3

Publishing events separates components in three practical ways:

  • It removes direct knowledge of subscribers: the publisher reports an occurrence and continues working. section 1.5.2 section 1.5.3
  • It tolerates delayed handling: subscribers can receive events later, as long as they eventually receive them. section 1.5.3
  • It isolates failures and location: conversations can continue while subscribers restart, even when components run on different servers. section 1.5.3

Container cargo history

Model a container with AddCargo as a command, CargoAdded as an event, and a State holding its cargo list. An EventSourcedBehavior uses a command handler to choose an Effect and event, then an event handler to derive the next state. On restart, replaying stored CargoAdded events reconstructs the container’s last known state. section 9.2 section 9.2.1

A persistent event is therefore both history and recovery input: restarting does not require a separately updated current-state record, because the actor reads its journal and replays events. In clustered use, persistent actor identity must be unique; Akka Sharding can combine entity identity with a type key to prevent collisions across nodes or entity types. section 9.2 section 9.2.1

How Akka in Action, Second Edition covers it

How deep it goes
Defines events, traces command validation through journal storage and replay, and outlines typed handlers without fully detailing their implementation.
Examples
Uses conversation message publication, mentions notifications, browser delivery, and a cargo container with AddCargo and CargoAdded.
What it assumes
Assumes familiarity with actors and messages, then introduces event sourcing through commands, events, state, and handlers.
What you can do after
Apply it via Akka Persistence to model accepted commands as stored events and recover state by replaying a journal.
How it connects
Connects events to commands, journals, event sourcing, publish-subscribe, persistent actors, Akka Sharding, and EventSourcedBehavior.

Also explained in

Compare how 18 books explain event →

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.