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§
Required Methods§
Sourcefn aggregate_id(&self) -> Self::AggregateId
fn aggregate_id(&self) -> Self::AggregateId
Routing key — which aggregate instance should handle this command.
Provided Methods§
Sourcefn expected_version(&self) -> Option<u64>
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).
Sourcefn command_id(&self) -> Option<&str>
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).