Crate eventsourced

source ·
Expand description

Event sourced entities.

EventSourced is inspired to a large degree by the amazing Akka Persistence library. It provides a framework for implementing Event Sourcing and CQRS.

The EvtLog and SnapshotStore traits define a pluggable event log and a pluggable snapshot store respectively. For NATS and Postgres these are implemented in the respective crates.

The spawn function provides for creating event sourced entities, identifiable by an ID, for some event log and some snapshot store. Conversion of events and snapshot state to and from bytes happens via the given Binarize implementation; for prost and serde_json these are already provided.

Calling spawn results in a cloneable EntityRef which can be used to pass commands to the spawned entity by invoking handle_cmd. Commands are handled by the command handler of the spawned entity. They can be rejected by returning an error. Valid commands produce an event which gets persisted to the EvtLog and then applied to the event handler of the respective entity. Snapshots can be taken to speed up future spawning.

Events can be queried from the event log by ID or by entity type. These queries can be used to build read side projections. There is early support for projections in the eventsourced-projection crate.

Modules§

Structs§

Enums§

  • Error from spawning an event sourced entity.

Traits§