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//! ### Span Fields
34//!
35//! Each trace span includes the following fields:
36//!
37//! - `correlation_id`: Unique identifier that links all spans in a single message flow
38//! - `route_id`: Identifier for the route being traced
39//! - `step_id`: Unique identifier for this specific step in the route
40//! - `step_index`: Sequential index of this step within the route
41//! - `timestamp`: When the step was executed (Unix timestamp)
42//! - `duration_ms`: How long the step took to execute in milliseconds
43//! - `status`: The status of the step execution (e.g., "success", "error")
44//!
45//! ### Detail Levels
46//!
47//! The tracer supports three levels of detail:
48//!
49//! - **Minimal**: Includes only the base fields listed above
50//! - **Medium**: Includes the base fields plus:
51//!   - `headers_count`: Number of message headers
52//!   - `body_type`: Type of the message body
53//!   - `has_error`: Whether the message contains an error
54//!   - `output_body_type`: Type of the output body after processing
55//! - **Full**: Includes all fields from Minimal and Medium plus:
56//!   - Up to 3 message headers (`header_0`, `header_1`, `header_2`)
57//!
58//! //! Configuration types for the Tracer EIP live in `camel-core` rather than `camel-config`
59//! //! to avoid a circular dependency — `camel-config` depends on `camel-core`.
60//!
61pub mod cache;
62pub mod claim_check;
63pub mod component_metadata_catalog;
64pub mod context;
65mod context_builder;
66pub mod datasource;
67pub mod health_registry;
68pub(crate) mod hot_reload;
69pub mod idempotent;
70pub mod language_registry;
71pub mod lifecycle;
72mod registry;
73// Re-export idempotent registry types for use in lifecycle layers (which
74// are forbidden by the hexagonal boundary test from importing
75// `crate::registry::` directly). Use `crate::IdempotentRegistry` etc.
76pub(crate) use registry::{
77    CacheRegistry, ClaimCheckRegistry, IdempotentRegistry, SharedCacheRegistry,
78    SharedClaimCheckRegistry, SharedIdempotentRegistry,
79};
80pub mod intercept;
81pub(crate) mod shared;
82pub mod startup_validation;
83pub mod step;
84pub mod template;
85
86#[cfg(feature = "export-internal-adapters")]
87pub mod route {
88    pub use crate::lifecycle::adapters::route_compiler::{
89        PipelineRuntimeCtx, RouteChannelService, compose_pipeline, compose_pipeline_with_contracts,
90        compose_pipeline_with_handler, compose_traced_pipeline,
91    };
92    pub use crate::lifecycle::adapters::route_types::Route;
93    pub use crate::lifecycle::adapters::step_compilers::CompiledStep;
94    pub use crate::lifecycle::application::route_definition::*;
95    pub use crate::lifecycle::domain::route::RouteSpec;
96}
97
98#[cfg(feature = "export-internal-adapters")]
99pub mod route_controller {
100    pub use crate::lifecycle::adapters::route_controller::*;
101    pub use crate::lifecycle::adapters::route_controller_trait::{
102        BindExposureAcks, enforce_bind_exposure_gate,
103    };
104}
105
106pub mod supervising_route_controller {
107    pub use crate::lifecycle::adapters::controller_actor::spawn_supervision_task;
108}
109
110pub mod reload_watcher {
111    pub use crate::hot_reload::adapters::reload_watcher::*;
112    pub use crate::hot_reload::application::FunctionReloadContext;
113    pub use crate::hot_reload::application::execute_reload_actions;
114    pub use crate::hot_reload::domain::ReloadAction;
115}
116
117pub use crate::hot_reload::adapters::ReloadWatcher;
118pub use crate::hot_reload::application::FunctionReloadContext;
119pub use crate::hot_reload::application::execute_reload_actions;
120pub use crate::hot_reload::domain::ReloadAction;
121#[cfg(feature = "export-internal-adapters")]
122pub use crate::idempotent::RedbIdempotentRepository;
123pub use crate::language_registry::LanguageRegistryError;
124pub use crate::lifecycle::adapters::controller_actor::RouteControllerHandle;
125pub use crate::lifecycle::adapters::controller_actor::spawn_controller_actor;
126pub use crate::lifecycle::adapters::controller_actor::spawn_supervision_task;
127#[cfg(feature = "export-internal-adapters")]
128pub use crate::lifecycle::adapters::exchange_uow::ExchangeUoWLayer;
129#[cfg(feature = "export-internal-adapters")]
130pub use crate::lifecycle::adapters::redb_journal::{
131    JournalDurability, JournalEntry, JournalInspectFilter, RedbJournalOptions,
132    RedbRuntimeEventJournal,
133};
134
135#[cfg(feature = "export-internal-adapters")]
136pub use crate::lifecycle::adapters::route_controller::DefaultRouteController;
137#[cfg(feature = "export-internal-adapters")]
138pub use crate::lifecycle::adapters::route_types::Route;
139#[cfg(feature = "export-internal-adapters")]
140pub use crate::lifecycle::adapters::{
141    InMemoryCommandDedup, InMemoryEventPublisher, InMemoryProjectionStore, InMemoryRouteRepository,
142    InMemoryRuntimeStore, RuntimeExecutionAdapter,
143};
144pub use crate::lifecycle::application::ports::{
145    CommandDedupPort, EventPublisherPort, InFlightCountResult, ProjectionStorePort,
146    RouteRepositoryPort, RouteStatusProjection, RuntimeEventJournalPort, RuntimeExecutionPort,
147    RuntimeUnitOfWorkPort,
148};
149pub use crate::lifecycle::application::runtime_bus::RuntimeBus;
150pub use crate::lifecycle::application::{BuilderStep, RouteDefinition};
151pub use crate::lifecycle::domain::{
152    RouteLifecycleCommand, RouteRuntimeAggregate, RouteRuntimeState, RuntimeEvent,
153};
154pub use crate::shared::components::domain::Registry;
155pub use crate::shared::components::domain::RegistryComponentContext;
156pub use crate::shared::observability::adapters::TracingProcessor;
157pub use crate::shared::observability::domain::{
158    DetailLevel, FileOutput, OutputFormat, StdoutOutput, TracerConfig, TracerOutputs,
159};
160pub use context::CamelContext;
161pub use language_registry::from_config as languages_from_config;
162pub use template::TemplateRegistry;
163
164// Re-export route controller types from camel-api (they live there to avoid cyclic dependencies).
165pub use camel_api::CamelError;
166pub use camel_api::{RouteAction, RouteController, RouteStatus};
167
168impl From<lifecycle::domain::DomainError> for CamelError {
169    fn from(e: lifecycle::domain::DomainError) -> Self {
170        CamelError::RouteError(e.to_string())
171    }
172}
173
174impl From<crate::language_registry::LanguageRegistryError> for CamelError {
175    fn from(e: crate::language_registry::LanguageRegistryError) -> Self {
176        CamelError::Config(e.to_string())
177    }
178}