Skip to main content

camel_component/
endpoint.rs

1use camel_api::{BodyType, BoxProcessor, CamelError};
2
3use crate::ProducerContext;
4use crate::consumer::Consumer;
5
6/// An Endpoint represents a source or destination in a route URI.
7pub trait Endpoint: Send + Sync {
8    /// The URI that identifies this endpoint.
9    fn uri(&self) -> &str;
10
11    /// Create a consumer that reads from this endpoint.
12    fn create_consumer(&self) -> Result<Box<dyn Consumer>, CamelError>;
13
14    /// Create a producer that writes to this endpoint.
15    fn create_producer(&self, ctx: &ProducerContext) -> Result<BoxProcessor, CamelError>;
16
17    /// Optional body type contract for the producer.
18    ///
19    /// When `Some(t)`, the pipeline will coerce the body to `t` before calling
20    /// the producer. Default: `None` (accept any body variant, zero overhead).
21    fn body_contract(&self) -> Option<BodyType> {
22        None
23    }
24}