feat: wire NATS event publisher into bootstrap + worker

- Both binaries connect to NATS on startup, ensure JetStream stream
- EventPublisherAdapter<NatsTransport> replaces LogEventPublisher
- nats_url config with default nats://localhost:4222
- Deleted bootstrap's LogEventPublisher (no longer needed)
This commit is contained in:
2026-05-31 11:53:51 +02:00
parent 0e9911ebfc
commit 838ed9a3f8
11 changed files with 35 additions and 36 deletions

View File

@@ -3,6 +3,7 @@ pub struct Config {
pub host: String,
pub port: u16,
pub database_url: String,
pub nats_url: String,
pub jwt_secret: String,
pub cors_allowed_origins: Vec<String>,
}
@@ -17,6 +18,8 @@ impl Config {
.and_then(|p| p.parse().ok())
.unwrap_or(3000),
database_url: std::env::var("DATABASE_URL").expect("DATABASE_URL must be set"),
nats_url: std::env::var("NATS_URL")
.unwrap_or_else(|_| "nats://localhost:4222".to_string()),
jwt_secret: std::env::var("JWT_SECRET").expect("JWT_SECRET must be set"),
cors_allowed_origins: std::env::var("CORS_ALLOWED_ORIGINS")
.unwrap_or_else(|_| "http://localhost:3000".to_string())

View File

@@ -55,13 +55,15 @@ use presentation::{
};
use crate::config::Config;
use crate::log_event_publisher::LogEventPublisher;
use crate::log_sidecar_writer::LogSidecarWriter;
pub async fn build_app(config: &Config) -> Result<Router> {
let pool = connect(&config.database_url).await?;
run_migrations(&pool).await?;
let nats_client = async_nats::connect(&config.nats_url).await?;
adapters_nats::ensure_stream(&nats_client).await?;
// Identity
let user_repo = Arc::new(PostgresUserRepository::new(pool.clone()));
let hasher = Arc::new(BcryptPasswordHasher);
@@ -91,7 +93,9 @@ pub async fn build_app(config: &Config) -> Result<Router> {
let batch_repo = Arc::new(PostgresJobBatchRepository::new(pool.clone()));
let plugin_repo = Arc::new(PostgresPluginRepository::new(pool.clone()));
let pipeline_repo = Arc::new(PostgresPipelineRepository::new(pool.clone()));
let event_publisher: Arc<LogEventPublisher> = Arc::new(LogEventPublisher);
let transport = adapters_nats::NatsTransport::new(nats_client);
let event_publisher: Arc<dyn domain::ports::EventPublisher> =
Arc::new(event_transport::EventPublisherAdapter::new(transport));
let sidecar_writer: Arc<LogSidecarWriter> = Arc::new(LogSidecarWriter);
// File storage

View File

@@ -1,4 +1,3 @@
pub mod config;
pub mod factory;
pub mod log_event_publisher;
pub mod log_sidecar_writer;

View File

@@ -1,12 +0,0 @@
use async_trait::async_trait;
use domain::{errors::DomainError, events::DomainEvent, ports::EventPublisher};
pub struct LogEventPublisher;
#[async_trait]
impl EventPublisher for LogEventPublisher {
async fn publish(&self, event: &DomainEvent) -> Result<(), DomainError> {
tracing::info!(?event, "domain event published");
Ok(())
}
}

View File

@@ -3,7 +3,6 @@ use tracing::info;
mod config;
mod factory;
mod log_event_publisher;
mod log_sidecar_writer;
#[tokio::main]