pipeflow 0.0.4

A lightweight, configuration-driven data pipeline framework
Documentation
//! Blackhole sink that discards all messages
//!
//! This sink is useful for benchmarking or intentionally ignoring data.

use async_trait::async_trait;

use crate::common::message::SharedMessage;
use crate::error::Result;
use crate::sink::Sink;

/// Blackhole sink that silently discards all messages
pub struct BlackholeSink {
    id: String,
}

impl BlackholeSink {
    /// Create a new blackhole sink with the given ID
    pub fn new(id: impl Into<String>) -> Self {
        Self { id: id.into() }
    }
}

#[async_trait]
impl Sink for BlackholeSink {
    fn id(&self) -> &str {
        &self.id
    }

    async fn process(&self, _msg: SharedMessage) -> Result<()> {
        // Silently discard the message
        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::common::message::Message;
    use serde_json::json;
    use std::sync::Arc;

    #[tokio::test]
    async fn test_blackhole_sink() {
        let sink = BlackholeSink::new("test_blackhole");
        assert_eq!(sink.id(), "test_blackhole");

        let msg = Arc::new(Message::new("source", json!({"data": 123})));
        let result = sink.process(msg).await;
        assert!(result.is_ok());
    }
}