Skip to main content

ProcessManagerDomainHandler

Trait ProcessManagerDomainHandler 

Source
pub trait ProcessManagerDomainHandler<S>: Send + Sync {
    // Required methods
    fn event_types(&self) -> Vec<String>;
    fn prepare(&self, trigger: &EventBook, state: &S, event: &Any) -> Vec<Cover>;
    fn handle(
        &self,
        trigger: &EventBook,
        state: &S,
        event: &Any,
        destinations: &[EventBook],
    ) -> CommandResult<ProcessManagerResponse>;

    // Provided method
    fn on_rejected(
        &self,
        _notification: &Notification,
        _state: &S,
        _target_domain: &str,
        _target_command: &str,
    ) -> CommandResult<RejectionHandlerResponse> { ... }
}
Expand description

Handler for a single domain’s events in a process manager.

Process managers correlate events across multiple domains and maintain their own state. Each domain gets its own handler, but they all share the same PM state type.

§Example

struct OrderPmHandler;

impl ProcessManagerDomainHandler<HandFlowState> for OrderPmHandler {
    fn event_types(&self) -> Vec<String> {
        vec!["OrderCreated".into()]
    }

    fn prepare(&self, trigger: &EventBook, state: &HandFlowState, event: &Any) -> Vec<Cover> {
        // Declare needed destinations
        vec![]
    }

    fn handle(
        &self,
        trigger: &EventBook,
        state: &HandFlowState,
        event: &Any,
        destinations: &[EventBook],
    ) -> CommandResult<ProcessManagerResponse> {
        // Process event, emit commands and/or PM events
        Ok(ProcessManagerResponse::default())
    }
}

Required Methods§

Source

fn event_types(&self) -> Vec<String>

Event type suffixes this handler processes.

Source

fn prepare(&self, trigger: &EventBook, state: &S, event: &Any) -> Vec<Cover>

Prepare phase — declare destination covers needed.

Source

fn handle( &self, trigger: &EventBook, state: &S, event: &Any, destinations: &[EventBook], ) -> CommandResult<ProcessManagerResponse>

Handle phase — produce commands and PM events.

Provided Methods§

Source

fn on_rejected( &self, _notification: &Notification, _state: &S, _target_domain: &str, _target_command: &str, ) -> CommandResult<RejectionHandlerResponse>

Handle a rejection notification.

Called when a PM-issued command was rejected. Override to provide custom compensation logic.

Implementors§