Skip to main content

CqrsBuilder

Struct CqrsBuilder 

Source
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,

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn snapshot_store<S: SnapshotStore + ?Sized>(self, store: Arc<S>) -> Self
where Arc<S>: Into<Arc<dyn SnapshotStore>>,

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.

Source

pub fn snapshot_policy(self, policy: SnapshotPolicy) -> Self

Override the snapshot cadence policy. Default: Manual (no auto-snapshots; users must call save_snapshot themselves).

Source

pub fn snapshot_keep_last(self, n: usize) -> Self

Cap on retained snapshots per persistence id. Default: 1.

Source

pub fn name(self, name: impl Into<String>) -> Self

Set the user-guardian name for this pattern’s root actor. Default: "cqrs".

Source

pub fn factory<F>(self, factory: F) -> Self
where F: Fn(<A as AggregateRoot>::Id) -> A + Send + Sync + 'static,

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.

Source

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.

Source

pub fn recovery_permits(self, n: usize) -> Self

Cap on concurrently-recovering aggregates. Default: 8.

Source

pub fn poll_interval(self, d: Duration) -> Self

How often the reader runners poll the read journal. Default: 50ms.

Source

pub fn repository_timeout(self, d: Duration) -> Self

Timeout the Repository applies to each ask. Default: 5s.

Source

pub fn writer_uuid(self, w: impl Into<String>) -> Self

Override the writer UUID stamped onto every persisted event.

Source

pub fn on_command<F>(self, hook: F) -> Self
where F: Fn(&A::Command) -> Result<(), PatternError<A::Error>> + Send + Sync + 'static,

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).

Source

pub fn on_event<F>(self, hook: F) -> Self
where F: Fn(&A::Event) + Send + Sync + 'static,

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.

Source

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.

Source

pub fn with_reader<R>( self, reader: R, ) -> (Self, ProjectionHandle<R::Projection>)
where R: Reader<Event = A::Event>,

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.

Source

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.

Auto Trait Implementations§

§

impl<A, J> Freeze for CqrsBuilder<A, J>
where <A as Eventsourced>::Event: Sized,

§

impl<A, J> !RefUnwindSafe for CqrsBuilder<A, J>

§

impl<A, J> Send for CqrsBuilder<A, J>
where <A as Eventsourced>::Event: Sized,

§

impl<A, J> Sync for CqrsBuilder<A, J>
where <A as Eventsourced>::Event: Sized,

§

impl<A, J> Unpin for CqrsBuilder<A, J>
where <A as Eventsourced>::Event: Sized,

§

impl<A, J> UnsafeUnpin for CqrsBuilder<A, J>
where <A as Eventsourced>::Event: Sized,

§

impl<A, J> !UnwindSafe for CqrsBuilder<A, J>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Extension for T
where T: Any + Send + Sync,