use std::collections::HashMap; use lombok::{Builder, Getter, Setter}; #[derive( serde::Deserialize, serde::Serialize, Debug, Clone, PartialEq, Eq, Getter, Setter, Builder, )] #[serde(default)] pub struct AppQueueSettings { pub enabled: bool, pub brokers: String, pub client_id: String, pub topic_prefix: String, pub default_group_id: String, pub message_timeout_ms: u32, pub session_timeout_ms: u32, pub auto_offset_reset: String, pub producer_compression: String, pub producer_acks: String, pub publish_queue_timeout_ms: u32, pub subscribe_max_retries: u32, pub subscribe_graceful_shutdown_ms: u64, pub additional_properties: HashMap, } impl Default for AppQueueSettings { fn default() -> Self { Self { enabled: true, brokers: "127.0.0.1:9092".to_string(), client_id: "untitled".to_string(), topic_prefix: "untitled".to_string(), default_group_id: "untitled".to_string(), message_timeout_ms: 5_000, session_timeout_ms: 10_000, auto_offset_reset: "earliest".to_string(), producer_compression: "lz4".to_string(), producer_acks: "all".to_string(), publish_queue_timeout_ms: 1_000, subscribe_max_retries: 3, subscribe_graceful_shutdown_ms: 5_000, additional_properties: HashMap::new(), } } } impl AppQueueSettings { pub fn is_valid(&self) -> Result<(), String> { if !self.enabled { return Ok(()); } if self.brokers.trim().is_empty() { return Err("brokers must not be empty when enabled".to_string()); } if self.topic_prefix.is_empty() { return Err("topic_prefix must not be empty".to_string()); } match self.auto_offset_reset.as_str() { "earliest" | "latest" | "none" => {} other => { return Err(format!( "auto_offset_reset must be one of earliest|latest|none, got {other}" )); } } match self.producer_acks.as_str() { "0" | "1" | "all" => {} other => return Err(format!("producer_acks must be one of 0|1|all, got {other}")), } match self.producer_compression.as_str() { "none" | "gzip" | "snappy" | "lz4" | "zstd" => {} other => return Err(format!("producer_compression invalid: {other}")), } Ok(()) } }