camel-component-api
Component API traits and extension points for rust-camel components.
Overview
camel-component-api defines the core Component, Endpoint, Consumer, and Producer contracts used by component crates.
It also re-exports common types from camel-api and URI helpers from camel-endpoint, so most component crates can depend on a single API crate.
Features
Componenttrait for scheme-based endpoint factoriesEndpoint,Consumer, and producer context contracts- New extension traits:
ComponentContext,ComponentRegistrar,ComponentBundle NoOpComponentContexthelper for tests and examples- Re-exports from
camel-api(e.g.CamelError,Exchange,BoxProcessor) - Re-exports from
camel-endpoint(UriConfig,UriComponents,parse_uri) - Shared network retry primitives:
NetworkRetryPolicy,retry_async,retry_async_cancelable,is_retryable_camel_error
Installation
[]
= "*"
Usage
Implementing a Custom Component
use ;
;
Core Types
| Type | Description |
|---|---|
Component |
Factory for scheme-specific endpoints |
Endpoint |
Consumer/producer endpoint contract |
Consumer |
Pulls/receives exchanges from a source |
ProducerContext |
Runtime context for producer creation |
ConsumerContext |
Runtime context passed to consumers |
ComponentContext |
Read-only access to components, languages, and metrics |
ComponentRegistrar |
Dynamic component registration interface (Arc<dyn Component>) |
ComponentBundle |
Multi-scheme registration + TOML config contract |
NoOpComponentContext |
Lightweight test context with no registry lookups |
Extension Traits
use Arc;
use ;
// ComponentContext: provided to create_endpoint
// ComponentBundle: register multiple schemes from one config
;
// NoOpComponentContext: convenient for tests
let ctx = NoOpComponentContext;
let _endpoint = MyComponent.create_endpoint?;
Network Retry Helpers
Shared retry primitives for transient network reconnects. See ADR-0013 for the full migration decision tree.
NetworkRetryPolicy
Shared configuration for capped exponential backoff with jitter:
use NetworkRetryPolicy;
use Duration;
let policy = NetworkRetryPolicy ;
Components expose this as a TOML [reconnect_policy] section:
[]
= 5
= 100
= 30000
= 2.0
= 0.1
= true
retry_async
Bounded retry of an async operation with a caller-provided classifier. The
optional label is emitted as a structured component tracing field and in
the retry log message for operator observability:
use ;
let result: = retry_async.await;
retry_async_cancelable
Same as retry_async, plus a CancellationToken
honored during the inter-retry sleep. Use for consumers/producers tied to
route shutdown so the backoff does not block cancellation:
use ;
use CancellationToken;
let result = retry_async_cancelable.await;
Cancel during op itself is the caller's responsibility (e.g. tokio::select!
in the op closure). Cancel during sleep returns the last operation error; no
synthetic Cancelled variant is added to the caller's error type.
is_retryable_camel_error
Canonical classifier for CamelError. Use when your operation already
returns CamelError and you want the standard retry-on-transient behavior
(CamelError::Io(_) and [TRANSIENT]-marked processor errors):
use ;
let result = retry_async.await;
When to use what
| Primitive | When |
|---|---|
retry_async |
Bounded retry of pure async ops, no shutdown-cancel need |
retry_async_cancelable |
Same + route/consumer shutdown interrupts backoff sleep |
| Manual loop | &mut state across await, polling/event-stream loops, async pre-retry side effects (bridge/pool restart), shared counters, non-idempotent writes |
Examples of each branch are listed in ADR-0013.
Documentation
License
Apache-2.0