When dispatching commands, you can choose how much to wait for side effects (like event handlers or process managers) to complete:
:eventual (default): Does not block. Returns immediately without waiting for any handlers. This offers low latency but means read models might be stale.:strong: Blocks until all strongly consistent event handlers and process managers have processed the resulting events. This ensures read models are up-to-date but increases latency. If handlers are not configured for strong consistency, this has no effect.- Explicit list: You can pass a list of specific handler modules or names
[Handler1, Handler2] to wait only for those specific handlers.
Handling Consistency Failures
If you use :strong consistency, a dispatch might return {:error, :consistency_timeout}. This means the command was successful, but the handlers did not finish within the dispatch_consistency_timeout period.
Configuration
You can set the global default consistency in your application config:
config :commanded, default_consistency: :strong
And the global timeout for strong consistency dispatch:
config :commanded, dispatch_consistency_timeout: 10_000
# Dispatch with strong consistency
case BankApp.dispatch(command, consistency: :strong) do
:ok -> # ... all ok
{:error, :consistency_timeout} -> # command ok, handlers have not yet executed
end
# Dispatch with specific handlers
:ok = BankApp.dispatch(command, consistency: [ExampleHandler, AnotherHandler])