Skip to main content

Command

Trait Command 

Source
pub trait Command: Send + 'static {
    type AggregateId: Clone + Eq + Hash + Send + Sync + 'static;

    // Required method
    fn aggregate_id(&self) -> Self::AggregateId;

    // Provided methods
    fn expected_version(&self) -> Option<u64> { ... }
    fn command_id(&self) -> Option<&str> { ... }
}
Expand description

A command targets exactly one crate::AggregateRoot (the transactional consistency boundary). The framework needs to know which aggregate before it can route the command, so every command must surface its target id.

Required Associated Types§

Source

type AggregateId: Clone + Eq + Hash + Send + Sync + 'static

Identity type of the aggregate this command targets.

Required Methods§

Source

fn aggregate_id(&self) -> Self::AggregateId

Routing key — which aggregate instance should handle this command.

Provided Methods§

Source

fn expected_version(&self) -> Option<u64>

Optional sequence the caller expects the aggregate to be at when this command runs. When Some(n), the gateway compares the entity’s current sequence number to n and returns crate::PatternError::ConcurrencyConflict on mismatch — i.e. optimistic concurrency control. Default: None (no check).

Source

fn command_id(&self) -> Option<&str>

Optional idempotency key. When the gateway has been configured with crate::cqrs::CqrsBuilder::dedupe_window (non-zero), commands with the same command_id for the same aggregate return the previous result without re-running the handler. Default: None (no dedupe).

Implementors§