use serde::{Deserialize, Serialize};
fn default_consumer_group() -> String {
"drasi-core".to_string()
}
fn default_batch_size() -> usize {
100
}
fn default_block_ms() -> u64 {
5000
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PlatformSourceConfig {
pub redis_url: String,
pub stream_key: String,
#[serde(default = "default_consumer_group")]
pub consumer_group: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub consumer_name: Option<String>,
#[serde(default = "default_batch_size")]
pub batch_size: usize,
#[serde(default = "default_block_ms")]
pub block_ms: u64,
}
impl PlatformSourceConfig {
pub fn validate(&self) -> anyhow::Result<()> {
if self.redis_url.is_empty() {
return Err(anyhow::anyhow!(
"Validation error: redis_url cannot be empty. \
Please provide a valid Redis connection URL (e.g., redis://localhost:6379)"
));
}
if self.stream_key.is_empty() {
return Err(anyhow::anyhow!(
"Validation error: stream_key cannot be empty. \
Please specify the Redis stream key to consume from"
));
}
if self.consumer_group.is_empty() {
return Err(anyhow::anyhow!(
"Validation error: consumer_group cannot be empty. \
Please specify a consumer group name"
));
}
if self.batch_size == 0 {
return Err(anyhow::anyhow!(
"Validation error: batch_size cannot be 0. \
Please specify a positive batch size"
));
}
Ok(())
}
}