Pular para o conteúdo
Português (BR)

ProjectionActor

Este conteúdo não está disponível em sua língua ainda.

Defined in: src/persistence/projection/ProjectionActor.ts:179

Actor wrapper around a projection. Owns the polling loop, the offset cursor, and the at-least-once delivery contract:

  1. preStart — load the cursor from OffsetStore.
  2. loop — poll the PersistenceQuery for new events from the cursor onwards.
  3. handle — call the user handler on each event. The handler MUST be idempotent — see at-least-once below.
  4. commit — save the cursor to the offset store.
  5. repeat.

At-least-once. If the projection crashes between step 3 and step 4, the next start replays from the saved cursor and the just-handled event will be re-handled. Handlers must therefore either:

  • be idempotent (e.g. UPSERT into the read model);
  • or do their own dedup via some unique key on the event.

Two query shapes are supported via the static factories:

  • ProjectionActor.byPersistenceId(...) — one cursor per pid. Use this for “give me everything an entity ever did”. The cursor is the entity’s sequenceNr.
  • ProjectionActor.byTag(...) — one cursor per tag. Use this for “give me every event labelled X across the whole journal”. The cursor is an Offset (timestamp + tiebreakers).

Stopping: the standard actorRef.stop() triggers postStop which cancels the polling timer; the in-flight handler call (if any) is awaited before the actor exits.

new ProjectionActor(): ProjectionActor

ProjectionActor

static byPersistenceId<E>(system, options): ActorRef<unknown>

Defined in: src/persistence/projection/ProjectionActor.ts:181

Spawn a per-persistenceId projection. Returns the actor ref.

E

ActorSystem

ByPersistenceIdProjectionOptions<E>

ActorRef<unknown>


static byTag<E>(system, options): ActorRef<unknown>

Defined in: src/persistence/projection/ProjectionActor.ts:194

Spawn a per-tag projection. Returns the actor ref.

E

ActorSystem

ByTagProjectionOptions<E>

ActorRef<unknown>