Outbound port for asynchronously sending commands.
Defines the CommandSenderPort ABC for dispatching commands via
an external message bus. Infrastructure implementations determine
delivery semantics.
Responsibilities
- Abstract command dispatch from transport details.
Non-Responsibilities
- Delivery guarantees (at-least-once, ordering, retries).
- Serialization or transport concerns.
CommandSenderPort
Bases: OutboundPort
ABC for dispatching command messages asynchronously.
Responsibilities
- Accept any domain command type and dispatch it asynchronously.
- Maintain a contract decoupled from any specific transport or
message bus implementation.
Non-Responsibilities
- Validate command payloads — that belongs to the validation layer.
- Implement retry, delivery guarantees, or dead-letter handling.
- Handle registration — registrations happen through a message bus,
not through this port.
Example
sender = MyCommandSender[PlaceOrderPayload]()
await sender.send(PlaceOrder(order_id="42"))
Source code in src/forging_blocks/application/ports/outbound/command_sender_port.py
| class CommandSenderPort[CommandPayloadType](
OutboundPort,
):
"""ABC for dispatching command messages asynchronously.
Responsibilities:
- Accept any domain command type and dispatch it asynchronously.
- Maintain a contract decoupled from any specific transport or
message bus implementation.
Non-Responsibilities:
- Validate command payloads — that belongs to the validation layer.
- Implement retry, delivery guarantees, or dead-letter handling.
- Handle registration — registrations happen through a message bus,
not through this port.
Example:
```python
sender = MyCommandSender[PlaceOrderPayload]()
await sender.send(PlaceOrder(order_id="42"))
```
"""
@abstractmethod
async def send(self, command: Command[CommandPayloadType]) -> None:
"""Send a command asynchronously.
Args:
command: The command instance to dispatch.
"""
|
send(command: Command[CommandPayloadType]) -> None
abstractmethod
async
Send a command asynchronously.
Parameters:
| Name |
Type |
Description |
Default |
command
|
Command[CommandPayloadType]
|
The command instance to dispatch.
|
required
|
Source code in src/forging_blocks/application/ports/outbound/command_sender_port.py
| @abstractmethod
async def send(self, command: Command[CommandPayloadType]) -> None:
"""Send a command asynchronously.
Args:
command: The command instance to dispatch.
"""
|