evento-core
Core types and traits for the Evento event sourcing library.
Overview
This crate provides the foundational types for building event-sourced applications:
- Events - Immutable records of state changes with ULID identifiers
- Aggregates - Domain entities that produce and consume events
- Projections - Read models built by replaying events
- Subscriptions - Continuous event processing with cursor tracking
- Executors - Storage abstraction for persisting and querying events
Features
macro(default) - Re-exports procedural macros fromevento-macrogroup- Multi-executor aggregation for querying across databasesrw- Read-write split executor for CQRS patternssqlite- SQLite database supportmysql- MySQL database supportpostgres- PostgreSQL database supportfjall- Embedded key-value storage with Fjall
Installation
Add to your Cargo.toml:
[]
= "2"
= "0.6"
Usage
Defining Aggregates and Events
// Define events using an enum
Creating Events
use ;
// Create a new aggregate with events
let account_id = create
.event
.metadata
.routing_key
.commit
.await?;
// Add events to existing aggregate
aggregator
.original_version
.event
.metadata
.commit
.await?;
Building Projections
Projections are used to load aggregate state by replaying events:
use ;
// Define projection state with cursor tracking
// Projection handlers update state from events
async
async
// Load aggregate state
let result =
.handler
.handler
.execute
.await?;
Running Subscriptions
Subscriptions process events in real-time with side effects:
use Duration;
use ;
// Subscription handlers receive context and can perform side effects
async
let subscription = new
.handler
.routing_key
.chunk_size
.retry
.delay
.start
.await?;
// On shutdown
subscription.shutdown.await?;
Cursor-based Pagination
use Args;
// Forward pagination
let args = forward;
let result = executor.read.await?;
// Continue from cursor
let args = forward;
let next_page = executor.read.await?;
// Backward pagination
let args = backward;
let result = executor.read.await?;
Core Types
Event
The raw event structure stored in the database:
Executor Trait
The core storage abstraction:
License
See the LICENSE file in the repository root.