Skip to main content

coreon_eip/
wiretap.rs

1//! WireTap — send a clone of the exchange to another endpoint, fire-and-forget.
2//!
3//! Runs the tap branch on a tokio task; the main pipeline continues
4//! immediately. Matches Camel's wireTap semantics.
5
6use async_trait::async_trait;
7use coreon_core::{Exchange, Processor, Result};
8use std::sync::Arc;
9use tracing::warn;
10
11pub struct WireTap {
12    branch: Arc<dyn Processor>,
13}
14
15impl WireTap {
16    pub fn new(branch: Arc<dyn Processor>) -> Arc<Self> {
17        Arc::new(Self { branch })
18    }
19}
20
21#[async_trait]
22impl Processor for WireTap {
23    async fn process(&self, exchange: &mut Exchange) -> Result<()> {
24        let mut copy = exchange.clone();
25        let branch = self.branch.clone();
26        tokio::spawn(async move {
27            if let Err(e) = branch.process(&mut copy).await {
28                warn!(error = %e, "wire-tap branch failed");
29            }
30        });
31        Ok(())
32    }
33}