pub struct CqrsBuilder<A, J>where
A: AggregateRoot,
A::Command: Command<AggregateId = <A as AggregateRoot>::Id>,
A::Event: DomainEvent,
J: Journal,{ /* private fields */ }Expand description
Fluent builder for a CQRS instance.
Implementations§
Source§impl<A, J> CqrsBuilder<A, J>where
A: AggregateRoot,
A::Command: Command<AggregateId = <A as AggregateRoot>::Id>,
A::Event: DomainEvent,
J: Journal,
impl<A, J> CqrsBuilder<A, J>where
A: AggregateRoot,
A::Command: Command<AggregateId = <A as AggregateRoot>::Id>,
A::Event: DomainEvent,
J: Journal,
Sourcepub fn dedupe_window(self, n: usize) -> Self
pub fn dedupe_window(self, n: usize) -> Self
Cap on the per-aggregate command-id dedupe ring. 0 (default)
disables dedupe — every command runs through the handler.
Non-zero enables idempotent retries: commands carrying a
previously-seen crate::Command::command_id return the
cached events without re-running the handler. v2 caches
successes only; failed commands always re-execute.
Sourcepub fn with_event_codecs(self, registry: EventCodecRegistry<A::Event>) -> Self
pub fn with_event_codecs(self, registry: EventCodecRegistry<A::Event>) -> Self
Provide an EventCodecRegistry that decodes events based on
their journal manifest. Lets you evolve event schemas without
rewriting old events.
Sourcepub fn with_reader_retry(
self,
max_attempts: u32,
schedule: RetrySchedule,
) -> Self
pub fn with_reader_retry( self, max_attempts: u32, schedule: RetrySchedule, ) -> Self
Reader runners retry transient apply failures up to
max_attempts times with the given backoff schedule.
Default: no retry — failures are logged and the offset
advances.
Sourcepub fn with_event_bus(self, bus: BusHandles<A::Event>) -> Self
pub fn with_event_bus(self, bus: BusHandles<A::Event>) -> Self
Wire a crate::bus::DomainEventBus into the gateway.
Persisted events are published to the bus on success, and
readers subscribe to the bus for live-tail delivery instead of
polling. Lower latency than polling at the cost of in-process
coupling to the bus’s lifetime.
Sourcepub fn shards(self, n: usize) -> Self
pub fn shards(self, n: usize) -> Self
Spawn n parallel command-gateway actors and route commands
across them by hashing crate::Command::aggregate_id. Per-id
FIFO ordering is preserved — every command for the same id
reaches the same gateway. v2 supports intra-process sharding
only; cross-node distribution via atomr-cluster-sharding is
a v3 follow-on.
Sourcepub fn snapshot_store<S: SnapshotStore + ?Sized>(self, store: Arc<S>) -> Self
pub fn snapshot_store<S: SnapshotStore + ?Sized>(self, store: Arc<S>) -> Self
Provide a SnapshotStore. When set together with
AggregateRoot::encode_state / AggregateRoot::decode_state,
the gateway prefers snapshots on recovery and saves new ones
according to Self::snapshot_policy.
Sourcepub fn snapshot_policy(self, policy: SnapshotPolicy) -> Self
pub fn snapshot_policy(self, policy: SnapshotPolicy) -> Self
Override the snapshot cadence policy. Default: Manual (no
auto-snapshots; users must call save_snapshot themselves).
Sourcepub fn snapshot_keep_last(self, n: usize) -> Self
pub fn snapshot_keep_last(self, n: usize) -> Self
Cap on retained snapshots per persistence id. Default: 1.
Sourcepub fn name(self, name: impl Into<String>) -> Self
pub fn name(self, name: impl Into<String>) -> Self
Set the user-guardian name for this pattern’s root actor.
Default: "cqrs".
Sourcepub fn factory<F>(self, factory: F) -> Self
pub fn factory<F>(self, factory: F) -> Self
Provide a factory that constructs a fresh aggregate for a given id. The framework calls this lazily — once per id — and reuses the instance for every subsequent command targeting that id.
Sourcepub fn read_journal<R: ReadJournal>(self, rj: Arc<R>) -> Self
pub fn read_journal<R: ReadJournal>(self, rj: Arc<R>) -> Self
Provide the read-side journal that readers subscribe to. Required
only if you register any readers via Self::with_reader.
Sourcepub fn recovery_permits(self, n: usize) -> Self
pub fn recovery_permits(self, n: usize) -> Self
Cap on concurrently-recovering aggregates. Default: 8.
Sourcepub fn poll_interval(self, d: Duration) -> Self
pub fn poll_interval(self, d: Duration) -> Self
How often the reader runners poll the read journal. Default: 50ms.
Sourcepub fn repository_timeout(self, d: Duration) -> Self
pub fn repository_timeout(self, d: Duration) -> Self
Timeout the Repository applies to each ask. Default: 5s.
Sourcepub fn writer_uuid(self, w: impl Into<String>) -> Self
pub fn writer_uuid(self, w: impl Into<String>) -> Self
Override the writer UUID stamped onto every persisted event.
Sourcepub fn on_command<F>(self, hook: F) -> Self
pub fn on_command<F>(self, hook: F) -> Self
Register a synchronous pre-handler interceptor (named slot
on_command). Returning Err short-circuits the persist with
PatternError::Intercepted (or any other variant the closure
constructs).
Sourcepub fn on_event<F>(self, hook: F) -> Self
pub fn on_event<F>(self, hook: F) -> Self
Register a synchronous post-persist event listener (named slot
on_event). Listeners run in the gateway’s actor task; keep
them fast — push to a tap if you need async work.
Sourcepub fn tap_events(self, tx: UnboundedSender<A::Event>) -> Self
pub fn tap_events(self, tx: UnboundedSender<A::Event>) -> Self
Register an async event tap. The runner pushes a clone of every successfully-persisted event into the channel. Closed receivers are pruned silently.
Sourcepub fn with_reader<R>(
self,
reader: R,
) -> (Self, ProjectionHandle<R::Projection>)
pub fn with_reader<R>( self, reader: R, ) -> (Self, ProjectionHandle<R::Projection>)
Register a Reader and receive a ProjectionHandle you
can use later to read the projection state. The reader’s
Event type must equal the aggregate’s Event type.
Sourcepub fn build(self) -> Result<CqrsTopology<A, J>, PatternError<A::Error>>
pub fn build(self) -> Result<CqrsTopology<A, J>, PatternError<A::Error>>
Finalize the builder. Returns a CqrsTopology that you call
Topology::materialize on to spawn the actors and start the
readers.