pub struct CommandBus { /* private fields */ }Expand description
Typed command router that maps concrete command types to aggregate handlers.
Unlike the CommandEnvelope-based dispatch used by process managers,
CommandBus routes commands by their Rust TypeId at zero runtime cost
(single HashMap lookup). Commands do not need to be serializable.
§Usage
use eventfold_es::{AggregateStore, CommandBus, CommandContext};
let store = AggregateStore::open("/tmp/my-app").await?;
let mut bus = CommandBus::new(store);
// bus.register::<MyAggregate>();
// bus.dispatch("instance-1", MyCommand { .. }, CommandContext::default()).await?;Implementations§
Source§impl CommandBus
impl CommandBus
Sourcepub fn new(store: AggregateStore) -> Self
pub fn new(store: AggregateStore) -> Self
Create a new CommandBus backed by the given store.
§Arguments
store- TheAggregateStoreused to look up and spawn aggregate actors.
Sourcepub async fn dispatch<C: Send + 'static>(
&self,
instance_id: &str,
cmd: C,
ctx: CommandContext,
) -> Result<(), DispatchError>
pub async fn dispatch<C: Send + 'static>( &self, instance_id: &str, cmd: C, ctx: CommandContext, ) -> Result<(), DispatchError>
Dispatch a command to the appropriate aggregate instance.
Looks up the route by TypeId::of::<C>() and delegates to the
registered aggregate’s actor.
§Arguments
instance_id- The target aggregate instance identifier.cmd- The concrete command to dispatch.ctx- Cross-cutting metadata (actor, correlation ID, etc.).
§Errors
DispatchError::UnknownCommand– no aggregate registered forC.DispatchError::Io– actor spawning or I/O failure.DispatchError::Execution– the aggregate rejected the command.
Auto Trait Implementations§
impl Freeze for CommandBus
impl !RefUnwindSafe for CommandBus
impl Send for CommandBus
impl Sync for CommandBus
impl Unpin for CommandBus
impl UnsafeUnpin for CommandBus
impl !UnwindSafe for CommandBus
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more