coreon-core 0.1.0

Core abstractions for camel-rs: Exchange, Processor, Endpoint, Component, CamelContext.
Documentation
//! Endpoint — addressable source/sink of exchanges.
//!
//! An Endpoint can produce (send a message to) or consume (receive messages
//! from) an underlying transport. Components create Endpoints from URIs.

use crate::{error::Result, exchange::Exchange, processor::Processor};
use async_trait::async_trait;
use std::sync::Arc;

/// Sends an Exchange into the endpoint's underlying transport.
#[async_trait]
pub trait Producer: Send + Sync {
    async fn send(&self, exchange: &mut Exchange) -> Result<()>;
}

/// Pulls exchanges off the underlying transport and feeds them to the
/// registered Processor pipeline. Consumers are started/stopped by the
/// route lifecycle.
#[async_trait]
pub trait Consumer: Send + Sync {
    async fn start(&self) -> Result<()>;
    async fn stop(&self) -> Result<()>;
}

/// An Endpoint is the bridge between URIs and Producer/Consumer pairs.
#[async_trait]
pub trait Endpoint: Send + Sync {
    fn uri(&self) -> &str;
    async fn create_producer(&self) -> Result<Arc<dyn Producer>>;
    async fn create_consumer(&self, pipeline: Arc<dyn Processor>) -> Result<Arc<dyn Consumer>>;
}