feat: event infrastructure — payload, transport, NATS adapter

- EventPublisher now takes &DomainEvent (11 call sites + 3 impls updated)
- EventEnvelope + EventConsumer port in domain
- event-payload: serializable DomainEvent mirror with subject routing
- event-transport: generic Transport/MessageSource traits, publisher/consumer adapters
- adapters-nats: JetStream publish + durable pull consumer
This commit is contained in:
2026-05-31 11:50:16 +02:00
parent dacfc3d453
commit 0e9911ebfc
24 changed files with 1294 additions and 21 deletions

View File

@@ -1,5 +1,12 @@
use crate::common::value_objects::{DateTimeStamp, SystemId};
pub struct EventEnvelope {
pub event: DomainEvent,
pub delivery_count: u64,
pub ack: Box<dyn Fn() + Send + Sync>,
pub nack: Box<dyn Fn() + Send + Sync>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum DomainEvent {
AssetIngested {

View File

@@ -1,8 +1,13 @@
use crate::common::errors::DomainError;
use crate::common::events::DomainEvent;
use crate::common::events::{DomainEvent, EventEnvelope};
use async_trait::async_trait;
use futures::stream::BoxStream;
#[async_trait]
pub trait EventPublisher: Send + Sync {
async fn publish(&self, event: DomainEvent) -> Result<(), DomainError>;
async fn publish(&self, event: &DomainEvent) -> Result<(), DomainError>;
}
pub trait EventConsumer: Send + Sync {
fn consume(&self) -> BoxStream<'_, Result<EventEnvelope, DomainError>>;
}