Identity

Add unique identifiers to messages.

Usage

Assigns a unique identifier to every message that passes through the handler.

The middleware will not touch any messages with an existing identifier. It will send them to the successive middleware without change.

Registration

Add the middleware to your bus.

bus = (
    banshee.builder()
    .with_middleware(banshee.IdentityMiddleware())
    .with_locator(registry)
    .build()
)

Context

An Identity context instance stores the unique identifier for a message.

unique_id = message[banshee.Identity].unique_id

Reference

class banshee.Identity(unique_id)

Bases: object

Identity context.

Attaches a unique identifier to the event.

Parameters

unique_id (UUID) – unique identifier

Return type

None

unique_id: UUID

unique identifier

class banshee.IdentityMiddleware(*args, **kwargs)

Bases: Middleware

Identity middleware.

Add unique identifiers for messages by adding an Identity context to each message with unique_id set to a unique identifier.

async __call__(message, handle)

Handle message.

Add a unique identifier to the message and forward it to the next handler in the chain.

Parameters
Returns

processed message

Return type

Message[T]