coreon-eip 0.1.0

Enterprise Integration Pattern processors for camel-rs.
Documentation
//! WireTap — send a clone of the exchange to another endpoint, fire-and-forget.
//!
//! Runs the tap branch on a tokio task; the main pipeline continues
//! immediately. Matches Camel's wireTap semantics.

use async_trait::async_trait;
use coreon_core::{Exchange, Processor, Result};
use std::sync::Arc;
use tracing::warn;

pub struct WireTap {
    branch: Arc<dyn Processor>,
}

impl WireTap {
    pub fn new(branch: Arc<dyn Processor>) -> Arc<Self> {
        Arc::new(Self { branch })
    }
}

#[async_trait]
impl Processor for WireTap {
    async fn process(&self, exchange: &mut Exchange) -> Result<()> {
        let mut copy = exchange.clone();
        let branch = self.branch.clone();
        tokio::spawn(async move {
            if let Err(e) = branch.process(&mut copy).await {
                warn!(error = %e, "wire-tap branch failed");
            }
        });
        Ok(())
    }
}