Skip to main content

CqrsCommandEngine

Struct CqrsCommandEngine 

Source
pub struct CqrsCommandEngine<A>
where A: Aggregate + CommandHandler + 'static, A::Error: Into<CqrsError>,
{ /* private fields */ }
Expand description

The CqrsCommandEngine struct is a Command Query Responsibility Segregation (CQRS) engine designed to handle commands and communication with an underlying event store and various dispatchers. It acts as the main entry point for command processing and encapsulates the behavior specific to an aggregate.

§Type Parameters

  • A: The type of the aggregate managed by this CQRS engine. The aggregate represents the domain behavior and state transitions.
  • ES: The type of the event store used to views events related to the aggregate.

§Bounds

  • A: Must implement the Aggregate trait. This ensures the aggregate provides necessary functionality such as validating commands or applying events to mutate its state.
  • ES: Must implement the EventStore<A> trait. This ensures the event store works with the specified aggregate type for persisting and retrieving events.

§Fields

  • store: ES The event store instance used to views and retrieve events associated with the aggregate. It allows the CQRS engine to save and load the aggregate’s event stream to/from persistent storage.

  • dispatchers: Vec<Box<dyn Dispatcher<A>>> A collection of dispatchers used by the CQRS engine to handle various external interactions such as messaging or integration with other systems. Dispatchers are responsible for forwarding or broadcasting events and can implement custom logic based on the use case.

  • services: A::Services A collection of domain-specific services required by the aggregate to perform its business operations. These services are defined within the aggregate’s associated types to provide dependencies such as external APIs, configuration, or infrastructure required for executing commands.

§Usage

Typically, the CqrsCommandEngine is instantiated with a concrete implementation of an event store, one or more command dispatchers, and the services needed by the aggregate. Once initialized, it can be used to dispatch commands and manage the lifecycle of aggregate instances.

This struct facilitates the CQRS pattern by separating the responsibility of command handling from querying, while keeping event storage and dispatching modular and configurable.

Implementations§

Source§

impl<A> CqrsCommandEngine<A>
where A: Aggregate + CommandHandler + 'static, A::Error: Into<CqrsError>,

Source

pub fn new( store: DynEventStore<A>, dispatchers: Vec<Box<dyn Dispatcher<A> + Send + Sync>>, services: A::Services, error_handler: Box<dyn Fn(&CqrsError) + Send + Sync>, ) -> Self

Source

pub fn with_id_generator( self, id_generator: Box<dyn AggregateIdGenerator<A> + Send + Sync>, ) -> Self

Source

pub fn append_dispatcher( &mut self, dispatcher: Box<dyn Dispatcher<A> + Send + Sync>, )

Source

pub async fn execute_create( &self, command: A::CreateCommand, context: &CqrsContext, ) -> Result<String, CqrsError>

Source

pub async fn execute_update( &self, aggregate_id: &str, command: A::UpdateCommand, context: &CqrsContext, ) -> Result<(), CqrsError>

Source

pub async fn execute_create_with_metadata( &self, command: A::CreateCommand, metadata: HashMap<String, String>, context: &CqrsContext, ) -> Result<String, CqrsError>

Source

pub async fn execute_update_with_metadata( &self, aggregate_id: &str, command: A::UpdateCommand, metadata: HashMap<String, String>, context: &CqrsContext, ) -> Result<(), CqrsError>

Auto Trait Implementations§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,