feat(infra): transactional outbox — OutboxWriter port, PgOutboxWriter, OutboxRelay, TestOutbox; update create_thought + delete_thought
This commit is contained in:
@@ -44,6 +44,11 @@ pub trait EventConsumer: Send + Sync {
|
||||
fn consume(&self) -> futures::stream::BoxStream<'_, Result<EventEnvelope, DomainError>>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait OutboxWriter: Send + Sync {
|
||||
async fn append(&self, event: &DomainEvent) -> Result<(), DomainError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait UserReader: Send + Sync {
|
||||
async fn find_by_id(&self, id: &UserId) -> Result<Option<User>, DomainError>;
|
||||
|
||||
@@ -937,6 +937,33 @@ impl EventPublisher for NoOpEventPublisher {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct TestOutbox {
|
||||
pub entries: Arc<Mutex<Vec<DomainEvent>>>,
|
||||
}
|
||||
|
||||
impl TestOutbox {
|
||||
pub fn staged(&self) -> Vec<DomainEvent> {
|
||||
self.entries.lock().unwrap().clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl OutboxWriter for TestOutbox {
|
||||
async fn append(&self, event: &DomainEvent) -> Result<(), DomainError> {
|
||||
self.entries.lock().unwrap().push(event.clone());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct NoOpOutboxWriter;
|
||||
#[async_trait]
|
||||
impl OutboxWriter for NoOpOutboxWriter {
|
||||
async fn append(&self, _e: &DomainEvent) -> Result<(), DomainError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod ap_repo_tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user