feat: Introduce MessageBroker abstraction for decoupled event publishing, add notes-worker service, and optimize note repository tag fetching.

This commit is contained in:
2025-12-26 01:31:36 +01:00
parent 58de25e5bc
commit 9ac013dce1
11 changed files with 238 additions and 115 deletions

View File

@@ -0,0 +1,31 @@
//! NATS message broker adapter for domain MessageBroker port
use async_trait::async_trait;
use notes_domain::{DomainError, DomainResult, MessageBroker, Note};
/// NATS adapter implementing the MessageBroker port
pub struct NatsMessageBroker {
client: async_nats::Client,
}
impl NatsMessageBroker {
pub fn new(client: async_nats::Client) -> Self {
Self { client }
}
}
#[async_trait]
impl MessageBroker for NatsMessageBroker {
async fn publish_note_updated(&self, note: &Note) -> DomainResult<()> {
let payload = serde_json::to_vec(note).map_err(|e| {
DomainError::RepositoryError(format!("Failed to serialize note: {}", e))
})?;
self.client
.publish("notes.updated", payload.into())
.await
.map_err(|e| DomainError::RepositoryError(format!("Failed to publish event: {}", e)))?;
Ok(())
}
}