Event Bus¶
event_bus
¶
Event Bus infrastructure.
This module provides the EventBusPort port and its in-memory implementation.
EventBusPort
¶
Bases: ABC
EventBusPort port.
The EventBusPort is responsible for publishing events and sending commands
to their respective handlers. It follows the publish-subscribe pattern
for events and the command pattern for commands.
Source code in src/forging_blocks/infrastructure/event_bus.py
publish(event: Event[Any]) -> None
abstractmethod
async
¶
Publish an event to all registered handlers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
Event[Any]
|
The event to publish. |
required |
send(command: Command[Any]) -> None
abstractmethod
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/event_bus.py
subscribe(event_type: Type[E], handler: EventHandler) -> None
abstractmethod
¶
Subscribe a handler to an event type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_type
|
Type[E]
|
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/event_bus.py
register_command_handler(command_type: Type[C], handler: CommandHandler) -> None
abstractmethod
¶
Register a handler for a command type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command_type
|
Type[C]
|
The type of command to handle. |
required |
handler
|
CommandHandler
|
The handler function to call when the command is sent. |
required |