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 given Binarizer functions; 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 with an optional tag which gets persisted to the EvtLog and then applied to the event handler of the respective entity. The event handler may decide to save a snapshot which is used to speed up future spawning.
Events can be queried from the event log by ID or by tag. These queries can be used to build read side projections.
Modules
Structs
- Collection of conversion functions from and to Bytes for events and snapshots.
- A handle for a spawned event sourced entity which can be used to invoke its command handler.
- A SnapshotStore implementation that does nothing.
- Snapshot state along with its sequence number.
Enums
- Error from an EntityRef.
- Error from spawning an event sourced entity.
Traits
- Command and event handling for an event sourced entity.
- Extension methods for types implementing EventSourced.
- Persistence for events.
- Persistence for snapshots.
- Extension methods for sequence numbers.
- Persistence for snapshots.
Functions
- Format the given error with its whole error chain, implemented by using
anyhow.