evoq_dispatcher (evoq v1.14.1)
View SourceCommand dispatcher with middleware pipeline.
Dispatches commands through the middleware chain to aggregates. Supports idempotency, retries, and consistency guarantees.
Dispatch Flow
1. Check idempotency cache 2. Create execution context 3. Run before_dispatch middleware 4. Get or start aggregate 5. Execute command on aggregate 6. Run after_dispatch or after_failure middleware 7. Handle consistency (wait for handlers if strong) 8. Cache result for idempotency
Summary
Functions
Dispatch a command through the middleware pipeline.
Dispatch a command and return the post-event aggregate state.
Functions
-spec dispatch(#evoq_command{command_id :: binary() | undefined, command_type :: atom() | undefined, aggregate_type :: atom() | undefined, aggregate_id :: binary() | undefined, payload :: map(), metadata :: map(), causation_id :: binary() | undefined, correlation_id :: binary() | undefined, idempotency_key :: binary() | undefined}, map()) -> {ok, non_neg_integer(), [map()]} | {error, term()}.
Dispatch a command through the middleware pipeline.
If command_id is undefined, auto-generates one. If idempotency_key is set, uses it for deduplication cache. Otherwise, command_id is used (each dispatch is unique).
-spec dispatch_with_state(#evoq_command{command_id :: binary() | undefined, command_type :: atom() | undefined, aggregate_type :: atom() | undefined, aggregate_id :: binary() | undefined, payload :: map(), metadata :: map(), causation_id :: binary() | undefined, correlation_id :: binary() | undefined, idempotency_key :: binary() | undefined}, map()) -> {ok, non_neg_integer(), [map()], term()} | {error, term()}.
Dispatch a command and return the post-event aggregate state.
Like dispatch/2 but includes the aggregate state after applying all new events. Enables session-level consistency where the caller receives immediate truth about the resulting state.