Skip to main content

made_core/ports/
messaging.rs

1//! [`MessagingPort`] — asynchronous message bus used to publish and
2//! consume domain events.
3//!
4//! The port speaks in domain-event terms; adapters map to/from NATS,
5//! Kafka, or any other substrate without leaking transport details
6//! into the core.
7
8use crate::error::DomainError;
9use crate::events::{
10    DeliberationCompletedEvent, PhaseChangedEvent, TaskCompletedEvent, TaskDispatchedEvent,
11    TaskFailedEvent,
12};
13use async_trait::async_trait;
14
15/// Publish / subscribe surface. Intentionally narrow: specific
16/// `publish_*` methods per event type enforce that publishing is a
17/// first-class, audited action — publishing an arbitrary untyped
18/// payload is not possible.
19#[async_trait]
20pub trait MessagingPort: Send + Sync {
21    async fn publish_task_dispatched(&self, event: &TaskDispatchedEvent)
22        -> Result<(), DomainError>;
23    async fn publish_task_completed(&self, event: &TaskCompletedEvent) -> Result<(), DomainError>;
24    async fn publish_task_failed(&self, event: &TaskFailedEvent) -> Result<(), DomainError>;
25    async fn publish_deliberation_completed(
26        &self,
27        event: &DeliberationCompletedEvent,
28    ) -> Result<(), DomainError>;
29    async fn publish_phase_changed(&self, event: &PhaseChangedEvent) -> Result<(), DomainError>;
30}