replace tokio::broadcast event bus with SQLite-backed event queue (ADR-0003)

- DomainEvent: add Serialize/Deserialize
- EventConsumer port: poll_next/ack/nack replacing recv()
- EventEnvelope: wraps event with id/retry_count/created_at
- SqliteEventPublisher/SqliteEventConsumer: INSERT/poll/DLQ
- migration: event_queue + dead_letter_queue tables
- InMemoryEventBus: combined publisher+consumer test double
- NoopEventConsumer: test stub
- webhook_consumer: polls EventConsumer instead of broadcast::Receiver
- presentation+mcp wiring: create from SqlitePool
This commit is contained in:
2026-07-12 07:23:21 +02:00
parent e2393be635
commit 826e824b58
13 changed files with 380 additions and 55 deletions

View File

@@ -1,7 +1,7 @@
use async_trait::async_trait;
use crate::errors::DomainResult;
pub use crate::events::DomainEvent;
pub use crate::events::{DomainEvent, EventEnvelope};
#[async_trait]
pub trait EventPublisher: Send + Sync {
@@ -10,7 +10,9 @@ pub trait EventPublisher: Send + Sync {
#[async_trait]
pub trait EventConsumer: Send + Sync {
async fn recv(&self) -> DomainResult<DomainEvent>;
async fn poll_next(&self) -> DomainResult<Option<EventEnvelope>>;
async fn ack(&self, event_id: i64) -> DomainResult<()>;
async fn nack(&self, event_id: i64, error: &str) -> DomainResult<()>;
}
#[async_trait]

View File

@@ -13,7 +13,7 @@ pub mod user;
pub use activity::{ActivityLogCommand, ActivityLogQuery};
pub use auth::{AuthService, TokenService};
pub use channel::{ChannelCommand, ChannelQuery};
pub use events::{DomainEvent, EventConsumer, EventHandler, EventPublisher};
pub use events::{DomainEvent, EventConsumer, EventEnvelope, EventHandler, EventPublisher};
pub use library::{LibraryCommand, LibraryQuery, LibrarySyncAdapter};
pub use media::{
Collection, IMediaProvider, IProviderRegistry, ProviderCapabilities, SeriesSummary,