1use async_trait::async_trait;
4use coreon_core::{CamelContext, Exchange, Processor, Result};
5use std::sync::{Arc, Weak};
6
7pub struct To {
13 uri: String,
14 ctx: Weak<CamelContext>,
15}
16
17impl To {
18 pub fn new(uri: impl Into<String>, ctx: &Arc<CamelContext>) -> Arc<Self> {
19 Arc::new(Self {
20 uri: uri.into(),
21 ctx: Arc::downgrade(ctx),
22 })
23 }
24}
25
26#[async_trait]
27impl Processor for To {
28 async fn process(&self, exchange: &mut Exchange) -> Result<()> {
29 let ctx = self
30 .ctx
31 .upgrade()
32 .ok_or_else(|| coreon_core::CamelError::NotRunning)?;
33 ctx.send(&self.uri, exchange).await
34 }
35}