Event Bus Port¶
event_bus_port
¶
Event bus port for publishing events and sending commands.
Defines the EventBusPort contract for in-process message dispatch
with separate policies for events (multi-handler fan-out) and commands
(single-handler routing).
EventBusPort
¶
Bases: OutboundPort
Abstract base class for event buses that publish events and send commands.
Responsibilities
- Publish domain events to all registered handlers (fan-out).
- Route commands to a single registered handler.
- Manage handler registration and lookup by message type.
Non-Responsibilities
- Guarantee delivery or implement transactional outbox.
- Persist messages or provide replay capabilities.
- Manage subscriptions, topics, or routing rules — those belong
to infrastructure.
Example
Source code in src/forging_blocks/application/ports/outbound/event_bus_port.py
publish(event: Event[EventPayloadType]) -> Result[None, EventBusError]
abstractmethod
async
¶
Publish a domain event to all registered handlers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
Event[EventPayloadType]
|
The domain event to publish. |
required |
Returns:
| Type | Description |
|---|---|
Result[None, EventBusError]
|
A |
Source code in src/forging_blocks/application/ports/outbound/event_bus_port.py
send(command: Command[CommandPayloadType]) -> Result[None, EventBusError]
abstractmethod
async
¶
Send a command to its registered handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
Command[CommandPayloadType]
|
The command to dispatch. |
required |
Returns:
| Type | Description |
|---|---|
Result[None, EventBusError]
|
A |
Source code in src/forging_blocks/application/ports/outbound/event_bus_port.py
register_handler(message_type: type[Event[EventPayloadType]] | type[Command[CommandPayloadType]], handler: HandlerType) -> None
abstractmethod
¶
Register a handler for the given message type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message_type
|
type[Event[EventPayloadType]] | type[Command[CommandPayloadType]]
|
The message class to handle. |
required |
handler
|
HandlerType
|
A handler instance implementing the handler contract. |
required |