[−][src]Trait krill::commons::eventsourcing::Command
Commands are used to send an intent to change an aggregate.
Think of this as the data container for your update API, plus some meta-data to ensure that the command is sent to the right instance of an Aggregate, and that concurrency issues are handled.
Associated Types
type Event: Event
Identify the type of event returned by the aggregate that uses this command. This is needed because we may need to check whether a command conflicts with recent events.
type StorableDetails: WithStorableDetails
Identify the type of storable component for this command. Commands
may contain short-lived things (e.g. an Arc
Required methods
fn handle(&self) -> &Handle
Identifies the aggregate, useful when storing and retrieving the event.
fn version(&self) -> Option<u64>
The version of the aggregate that this command updates. If this command should update whatever the latest version happens to be, then use None here.
fn store(&self) -> Self::StorableDetails
Get the storable information for this command
Provided methods
fn actor(&self) -> &str
The actor who sent the command. Defaults to "krill" so that it is not mandatory to implement this.
fn conflicts(&self, _events: &[Self::Event]) -> bool
In case of concurrent processing of commands, the aggregate may be outdated when a command is applied. In such cases this method expects the list of events that happened since the ['affected_version'] and will return whether there is a conflict. If there is no conflict that the command may be applied again.
Note that this defaults to true, which is the safe choice when in doubt. If you choose to implement this, then you will also need to implement the ['set_affected_version'] function.