camel-component-api 0.5.8

Component API trait and registry for rust-camel
Documentation

camel-component-api

Component API trait and registry for rust-camel

Overview

camel-component-api defines the core Component, Endpoint, Consumer, and Producer traits that all rust-camel components must implement. This crate provides the foundation for creating new components that can integrate with the rust-camel routing engine.

It also re-exports commonly used types from camel-api and camel-endpoint so that component crates only need a single dependency.

If you're building a custom component (e.g., for a proprietary protocol or service), you'll implement the traits defined in this crate.

Features

  • Component trait: Factory for creating endpoints from URIs
  • Endpoint trait: Represents a communication endpoint with consumer/producer support
  • Consumer trait: Consumes messages from external sources
  • Producer trait: Sends messages to external destinations
  • Concurrency support: Built-in support for concurrent message processing
  • Re-exports from camel-api: CamelError, Exchange, Message, Body, BodyType, BoxProcessor, Value, StreamBody, StreamMetadata, RouteStatus, RouteAction, RuntimeHandle, RuntimeCommandBus, RuntimeQueryBus, RuntimeCommand, RuntimeCommandResult, RuntimeQuery, RuntimeQueryResult
  • Re-exports from camel-endpoint: UriConfig, UriComponents, parse_uri

Installation

Add to your Cargo.toml:

[dependencies]
camel-component-api = "0.5"

Usage

Implementing a Custom Component

use camel_component_api::{Component, Endpoint, Consumer, ProducerContext, ConsumerContext, CamelError, BoxProcessor};

pub struct MyComponent;

impl Component for MyComponent {
    fn scheme(&self) -> &str {
        "mycomponent"
    }

    fn create_endpoint(&self, uri: &str) -> Result<Box<dyn Endpoint>, CamelError> {
        Ok(Box::new(MyEndpoint { uri: uri.to_string() }))
    }
}

struct MyEndpoint {
    uri: String,
}

impl Endpoint for MyEndpoint {
    fn uri(&self) -> &str {
        &self.uri
    }

    fn create_consumer(&self) -> Result<Box<dyn Consumer>, CamelError> {
        Ok(Box::new(MyConsumer))
    }

    fn create_producer(&self, ctx: &ProducerContext) -> Result<BoxProcessor, CamelError> {
        Err(CamelError::NotImplemented("producer not implemented".into()))
    }
}

Core Types

Type Description
Component Factory for creating endpoints
Endpoint Communication endpoint (consumer/producer)
Consumer Trait for consuming messages from endpoints
ConsumerContext Context provided to Consumer implementations
ProducerContext Context for creating producers
ExchangeEnvelope Message envelope with optional reply channel
ConcurrencyModel Sequential or Concurrent message processing

ConcurrencyModel

  • Sequential: Process messages one at a time in order. Use for simpler consumers where ordering matters.
  • Concurrent: Process multiple messages simultaneously. Use for higher throughput when order doesn't matter.

Documentation

License

Apache-2.0

Contributing

Contributions are welcome! Please see the main repository for details.