rust-camel
A Rust integration framework inspired by Apache Camel, built on Tower.
Status: Pre-release (
0.1.0). APIs will change.
Overview
rust-camel lets you define message routes between components using a fluent builder API. The data plane (exchange processing, EIP patterns, middleware) is Tower-native — every processor and producer is a Service<Exchange>. The control plane (components, endpoints, consumers, lifecycle) uses its own trait hierarchy.
Current components: timer, log, direct, mock, file.
Quick Example
use ;
use RouteBuilder;
use CamelContext;
use LogComponent;
use TimerComponent;
async
Crate Map
| Crate | Description |
|---|---|
camel-api |
Core types: Exchange, Message, CamelError, BoxProcessor, ProcessorFn |
camel-core |
Runtime: CamelContext, Route, RouteDefinition, SequentialPipeline |
camel-builder |
Fluent RouteBuilder API |
camel-component |
Component, Endpoint, Consumer traits |
camel-processor |
EIP processors: Filter, Splitter, Aggregator, WireTap, Multicast, SetHeader, MapBody + Tower Layer types |
camel-endpoint |
Endpoint URI parsing utilities |
camel-timer |
Timer source component |
camel-log |
Log sink component |
camel-direct |
In-memory synchronous component |
camel-mock |
Test component with assertions on received exchanges |
camel-test |
Integration test harness |
camel-controlbus |
Control routes dynamically from within routes |
Building & Testing
Implemented EIP Patterns
| Pattern | Builder Method | Description |
|---|---|---|
| Filter | .filter(predicate) |
Forward exchange only when predicate is true |
| Splitter | .split(config) |
Split one exchange into multiple fragments |
| Aggregator | .aggregate(config) |
Correlate and aggregate multiple exchanges |
| WireTap | .wire_tap(uri) |
Fire-and-forget copy to a tap endpoint |
| Multicast | .multicast() |
Send the same exchange to multiple endpoints |
| Content-Based Router | .choice() / .when() |
Route based on exchange content |
Run an example:
Security Features
rust-camel includes production-ready security features:
SSRF Protection (HTTP Component)
// Block private IPs by default
from
.to
.build?
// Custom blocked hosts
from
.to
.build?
Path Traversal Protection (File Component)
All file operations validate that resolved paths remain within the configured base directory. Attempts to use ../ or absolute paths outside base are rejected.
Timeouts
All I/O operations have configurable timeouts:
- File:
readTimeout,writeTimeout(default: 30s) - HTTP:
connectTimeout,responseTimeout
Memory Limits
Aggregator supports max_buckets and bucket_ttl to prevent memory leaks.
Observability
Correlation IDs
Every exchange has a unique correlation_id for distributed tracing.
Metrics
Implement MetricsCollector trait to integrate with Prometheus, OpenTelemetry, etc.
Route Lifecycle Management
rust-camel supports controlling when and how routes start:
Auto Startup
By default, all routes start automatically when ctx.start() is called. You can disable this:
let route = from
.route_id
.auto_startup // Won't start automatically
.to
.build?;
Startup Order
Control the order in which routes start (useful for dependencies):
let route_a = from
.route_id
.startup_order // Starts first
.to
.build?;
let route_b = from
.route_id
.startup_order // Starts after route-a
.to
.build?;
Runtime Control
Control routes dynamically from code or from other routes:
// From code:
ctx.route_controller.lock.await.start_route.await?;
ctx.route_controller.lock.await.stop_route.await?;
// From another route (using controlbus):
from
.set_header
.to
.build?
See examples/lazy-route for a complete example.
License
Apache-2.0