liveBook · Manning

EventEnvelope

As explained in Akka in Action, Second Edition

An EventEnvelope is a persistence-query data structure containing a journal event together with metadata such as its offset and persistence identifier.

An EventEnvelope wraps a journal event with the context needed to consume it through persistence queries. A typical envelope contains an offset, persistence identifier, sequence number, event payload, and timestamp. Queries return envelopes rather than bare events so streams and projections can track where each event came from. section 10.2 section 10.3.2

Reading and processing an envelope

A tagged query such as readJournal.eventsByTag("container-tag-0", Offset.noOffset) produces a Source[EventEnvelope, NotUsed]. One result can contain persistence ID "spcontainer-type-key|9", sequence number 1, and a CargoAdded event. A projection handler receives that envelope, pattern-matches envelope.event, and updates a repository when the event is relevant. section 10.2 section 10.3.2

Table 10.1 Methods available to consume the journal: inputs and outputs (view table figure)

Interface methods

Input

Output

eventsByTag

currentEventsByTag

tag: String

offset: Int

List[EventEnvelope]

persistenceIds

currentPersistenceIds

List[String]

eventsByPersistenceId

currentEventsByPersistenceId

id: String

from: Int

to: Int

List[EventEnvelope]

Compare persistence-query methods that return EventEnvelope streams, including tag queries and persistence-ID queries, with current and historical variants. section 10.2

How Akka in Action, Second Edition covers it

How deep it goes
Defines the wrapper and demonstrates its fields, then applies it in a JDBC projection without detailing envelope internals.
Examples
Uses tagged container events, CargoAdded payloads, and a cargo-per-container JDBC projection.
What it assumes
Assumes familiarity with journal events, persistence identifiers, offsets, streams, and event-sourced projections.
What you can do after
Apply it via Akka persistence queries and projection handlers to route journal events into database updates.
How it connects
Connects persistence queries with event tagging, journal events, event-sourced projections, and JDBC repositories.

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.