In Memory Event Bus¶
in_memory_event_bus
¶
In-memory implementation of the EventBusPort port.
This implementation stores handlers in memory and is suitable for testing
and development purposes.
InMemoryEventBus
¶
Bases: EventBusPort
In-memory implementation of the EventBusPort port.
Stores event handlers and command handlers in dictionaries.
Source code in src/forging_blocks/infrastructure/in_memory_event_bus.py
publish(event: Event[Any]) -> None
async
¶
Publish an event to all registered handlers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
Event[Any]
|
The event to publish. |
required |
Source code in src/forging_blocks/infrastructure/in_memory_event_bus.py
send(command: Command[Any]) -> None
async
¶
Send a command to its handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
Command[Any]
|
The command to send. |
required |
Raises:
| Type | Description |
|---|---|
NoHandlerError
|
If no handler is registered for the command type. |
Source code in src/forging_blocks/infrastructure/in_memory_event_bus.py
subscribe(event_type: Type[Event[Any]], handler: EventHandler) -> None
¶
Subscribe a handler to an event type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_type
|
Type[Event[Any]]
|
The type of event to subscribe to. |
required |
handler
|
EventHandler
|
The handler function to call when the event is published. |
required |
Source code in src/forging_blocks/infrastructure/in_memory_event_bus.py
register_command_handler(command_type: Type[Command[Any]], handler: CommandHandler) -> None
¶
Register a handler for a command type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command_type
|
Type[Command[Any]]
|
The type of command to handle. |
required |
handler
|
CommandHandler
|
The handler function to call when the command is sent. |
required |