camel-builder
Fluent route builder API for rust-camel
Overview
camel-builder provides a fluent, type-safe API for building routes in rust-camel. Inspired by Apache Camel's Java DSL, it allows you to define integration flows using method chaining with compile-time safety.
This is the primary way to define routes in rust-camel applications.
Routes can also be defined via YAML using camel-dsl. See the camel-dsl crate for details.
Features
- Fluent API: Intuitive method chaining for route definition
- Type Safety: Compile-time verification of route structure
- All EIP Patterns: Support for filter, split, multicast, aggregate, and more
- Error Handling: Configure error handlers per route
- Circuit Breaker: Built-in resilience pattern support
- Concurrency Control: Sequential or concurrent processing modes
- Route Lifecycle: Configure auto-startup and startup order
Installation
Add to your Cargo.toml:
[]
= "0.2"
Usage
Basic Route
use RouteBuilder;
use Value;
let route = from
.set_header
.log
.to
.build
.unwrap;
Filter and Branching
let route = from
.filter
.log
.to
.end_filter
.to
.build
.unwrap;
Content-Based Router (Choice)
use Value;
let route = from
.choice
.when
.to
.end_when
.when
.to
.end_when
.otherwise
.to
.end_otherwise
.end_choice
.build
.unwrap;
Message Transformation
use Body;
let route = from
.set_header
.map_body
.to
.build
.unwrap;
Splitter Pattern
use ;
let route = from
.split
.log
.to
.end_split
.to
.build
.unwrap;
Multicast Pattern
let route = from
.multicast
.parallel
.to
.to
.to
.end_multicast
.to
.build
.unwrap;
Script Step
Execute a script that can modify the Exchange in-place (headers, properties, body):
from
.script
.to
.route_id
.build?;
The language must be registered in the CamelContext. On error, all modifications are rolled back.
Error Handling
use ErrorHandlerConfig;
let route = from
.error_handler
.process
.to
.build
.unwrap;
Circuit Breaker
use CircuitBreakerConfig;
let route = from
.circuit_breaker
.to
.build
.unwrap;
Concurrency Control
// Concurrent processing (up to 16 in-flight)
let route = from
.concurrent
.process
.build
.unwrap;
// Sequential processing (ordered)
let route = from
.sequential
.process
.build
.unwrap;
Route Configuration
let route = from
.route_id
.auto_startup
.startup_order
.to
.build
.unwrap;
Builder Methods
| Method | Description |
|---|---|
from(uri) |
Start route from endpoint |
to(uri) |
Send to endpoint |
process(fn) |
Custom processing |
set_header(k, v) |
Set static header |
set_header_fn(k, fn) |
Set dynamic header |
set_body(v) |
Set static body |
set_body_fn(fn) |
Set dynamic body |
map_body(fn) |
Transform body |
filter(pred) |
Conditional routing |
choice() |
Open content-based router block |
when(pred) |
Open when-clause (inside choice) |
end_when() |
Close when-clause |
otherwise() |
Open fallback branch (inside choice) |
end_otherwise() |
Close fallback branch |
end_choice() |
Close content-based router block |
split(config) |
Split messages |
multicast() |
Parallel routing |
wire_tap(uri) |
Side-channel copy |
aggregate(config) |
Combine messages |
log(msg, level) |
Log message |
stop() |
Stop processing |
script(language, source) |
Execute a script that can modify headers, properties, and body |
error_handler(cfg) |
Set error handler |
circuit_breaker(cfg) |
Set circuit breaker |
concurrent(n) |
Enable concurrency |
sequential() |
Force sequential |
route_id(id) |
Set route ID |
auto_startup(bool) |
Auto-start control |
startup_order(n) |
Startup priority |
Documentation
License
Apache-2.0
Contributing
Contributions are welcome! Please see the main repository for details.