Skip to main content

camel_core/
lib.rs

1//! # Camel Core
2//!
3//! This crate provides the core functionality for the Apache Camel implementation in Rust.
4//!
5//! ## Tracer EIP
6//!
7//! The Tracer Enterprise Integration Pattern (EIP) provides automatic message flow tracing
8//! throughout your Camel routes. It captures detailed information about each step as messages
9//! flow through the integration routes, helping with debugging, monitoring, and observability.
10//!
11//! ### Configuration
12//!
13//! You can configure the tracer in your `Camel.toml` file:
14//!
15//! ```toml
16//! [observability.tracer]
17//! enabled = true
18//! detail_level = "minimal"  # minimal | medium | full
19//!
20//! [observability.tracer.outputs.stdout]
21//! enabled = true
22//! format = "json"
23//! ```
24//!
25//! Or enable it programmatically:
26//!
27//! ```ignore
28//! use camel_core::CamelContext;
29//! let mut ctx = CamelContext::builder().build().await.unwrap();
30//! ctx.set_tracing(true).await;
31//! ```
32//!
33//! ### Trace Data
34//!
35//! `camel_tracer` log records include `duration_ms`, `timestamp`, and `status`.
36//! OpenTelemetry span attributes include `messaging.system`, `route_id`, and
37//! `correlation_id` on root spans. Step and segment spans also include
38//! `step_index`.
39//!
40//! ### Detail Levels
41//!
42//! The tracer supports three levels of detail:
43//!
44//! - **Minimal**: Includes only the base fields listed above
45//! - **Medium**: Includes the base fields plus:
46//!   - `headers_count`: Number of message headers
47//!   - `body_type`: Type of the message body
48//!   - `has_error`: Whether the message contains an error
49//!   - `output_body_type`: Type of the output body after processing
50//! - **Full**: Includes all fields from Minimal and Medium plus:
51//!   - Up to 3 message headers (`header_0`, `header_1`, `header_2`)
52//!
53//! //! Configuration types for the Tracer EIP live in `camel-core` rather than `camel-config`
54//! //! to avoid a circular dependency — `camel-config` depends on `camel-core`.
55//!
56pub mod cache;
57pub mod claim_check;
58pub mod component_metadata_catalog;
59pub mod context;
60mod context_builder;
61pub mod datasource;
62pub mod health_registry;
63pub(crate) mod hot_reload;
64pub mod idempotent;
65pub mod language_registry;
66pub mod lifecycle;
67mod registry;
68// Re-export idempotent registry types for use in lifecycle layers (which
69// are forbidden by the hexagonal boundary test from importing
70// `crate::registry::` directly). Use `crate::IdempotentRegistry` etc.
71pub(crate) use registry::{
72    CacheRegistry, ClaimCheckRegistry, IdempotentRegistry, SharedCacheRegistry,
73    SharedClaimCheckRegistry, SharedIdempotentRegistry,
74};
75pub mod intercept;
76pub(crate) mod shared;
77pub mod startup_validation;
78pub mod step;
79pub mod template;
80
81#[cfg(feature = "export-internal-adapters")]
82pub mod route {
83    pub use crate::lifecycle::adapters::route_compiler::{
84        PipelineRuntimeCtx, RouteChannelService, compose_pipeline, compose_pipeline_with_contracts,
85        compose_pipeline_with_handler, compose_traced_pipeline,
86    };
87    pub use crate::lifecycle::adapters::route_types::Route;
88    pub use crate::lifecycle::adapters::step_compilers::CompiledStep;
89    pub use crate::lifecycle::application::route_definition::*;
90    pub use crate::lifecycle::domain::route::RouteSpec;
91}
92
93#[cfg(feature = "export-internal-adapters")]
94pub mod route_controller {
95    pub use crate::lifecycle::adapters::route_controller::*;
96    pub use crate::lifecycle::adapters::route_controller_trait::{
97        BindExposureAcks, enforce_bind_exposure_gate,
98    };
99}
100
101pub mod supervising_route_controller {
102    pub use crate::lifecycle::adapters::controller_actor::spawn_supervision_task;
103}
104
105pub mod reload_watcher {
106    pub use crate::hot_reload::adapters::reload_watcher::*;
107    pub use crate::hot_reload::application::FunctionReloadContext;
108    pub use crate::hot_reload::application::execute_reload_actions;
109    pub use crate::hot_reload::domain::ReloadAction;
110}
111
112pub use crate::hot_reload::adapters::ReloadWatcher;
113pub use crate::hot_reload::application::FunctionReloadContext;
114pub use crate::hot_reload::application::execute_reload_actions;
115pub use crate::hot_reload::domain::ReloadAction;
116#[cfg(feature = "export-internal-adapters")]
117pub use crate::idempotent::RedbIdempotentRepository;
118pub use crate::language_registry::LanguageRegistryError;
119pub use crate::lifecycle::adapters::controller_actor::RouteControllerHandle;
120pub use crate::lifecycle::adapters::controller_actor::spawn_controller_actor;
121pub use crate::lifecycle::adapters::controller_actor::spawn_supervision_task;
122#[cfg(feature = "export-internal-adapters")]
123pub use crate::lifecycle::adapters::exchange_uow::ExchangeUoWLayer;
124#[cfg(feature = "export-internal-adapters")]
125pub use crate::lifecycle::adapters::redb_journal::{
126    JournalDurability, JournalEntry, JournalInspectFilter, RedbJournalOptions,
127    RedbRuntimeEventJournal,
128};
129
130#[cfg(feature = "export-internal-adapters")]
131pub use crate::lifecycle::adapters::route_controller::DefaultRouteController;
132#[cfg(feature = "export-internal-adapters")]
133pub use crate::lifecycle::adapters::route_types::Route;
134#[cfg(feature = "export-internal-adapters")]
135pub use crate::lifecycle::adapters::{
136    InMemoryCommandDedup, InMemoryEventPublisher, InMemoryProjectionStore, InMemoryRouteRepository,
137    InMemoryRuntimeStore, RuntimeExecutionAdapter,
138};
139pub use crate::lifecycle::application::ports::{
140    CommandDedupPort, EventPublisherPort, InFlightCountResult, ProjectionStorePort,
141    RouteRepositoryPort, RouteStatusProjection, RuntimeEventJournalPort, RuntimeExecutionPort,
142    RuntimeUnitOfWorkPort,
143};
144pub use crate::lifecycle::application::runtime_bus::RuntimeBus;
145pub use crate::lifecycle::application::{BuilderStep, RouteDefinition};
146pub use crate::lifecycle::domain::{
147    RouteLifecycleCommand, RouteRuntimeAggregate, RouteRuntimeState, RuntimeEvent,
148};
149pub use crate::shared::components::domain::Registry;
150pub use crate::shared::components::domain::RegistryComponentContext;
151pub use crate::shared::observability::adapters::TracingProcessor;
152pub use crate::shared::observability::domain::{
153    DetailLevel, FileOutput, OutputFormat, StdoutOutput, TracerConfig, TracerOutputs,
154};
155pub use context::CamelContext;
156pub use language_registry::from_config as languages_from_config;
157pub use template::TemplateRegistry;
158
159// Re-export route controller types from camel-api (they live there to avoid cyclic dependencies).
160pub use camel_api::CamelError;
161pub use camel_api::{RouteAction, RouteController, RouteStatus};
162
163impl From<lifecycle::domain::DomainError> for CamelError {
164    fn from(e: lifecycle::domain::DomainError) -> Self {
165        CamelError::RouteError(e.to_string())
166    }
167}
168
169impl From<crate::language_registry::LanguageRegistryError> for CamelError {
170    fn from(e: crate::language_registry::LanguageRegistryError) -> Self {
171        CamelError::Config(e.to_string())
172    }
173}