The core of the command dispatcher.
ContextVar to store state per thread or async
Tracks the requests that trigger other request. The middleware will add a causation and correlation identifier to every message.
The causation identifier relates to the request that triggered this request.
The correlation identifier relates to the original request that triggered all parent requests. The request passed to the message bus.
Add the middleware to your bus. This middleware should come after the
bus = ( banshee.builder() .with_middleware(banshee.IdentityMiddleware()) .with_middleware(banshee.CausationMiddleware()) .with_locator(registry) .build() )
Causation context instance stores the causation and correlation
identifiers for the message.
causation_id = message[banshee.Causation].causation_id correlation_id = message[banshee.Causation].correlation_id
- class banshee.Causation(causation_id, correlation_id)
Holds the identity of the request that created this request, and the root request for correlating related events.
- Return type
- causation_id: UUID
- correlation_id: UUID
- class banshee.CausationMiddleware
Add causation and correlation identifiers to messages based on the messages
Identitycontext is present this handler will pass the message unchanged.
- Return type
- async __call__(message, handle)
Add causation and correlation identifiers to the message and forward it to the next handler in the chain.