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};
75// Public transaction-manager registry surface. Dark in slice 1 — nothing
76// registers a manager; camel-sql registers per datasource in slice 2
77// (rc-qv2iz.6).
78pub use registry::{RegistryError, TransactionManagerRegistry, resolve_transaction_manager};
79// Test-only doubles shared between the registry and `RuntimeBus` suites.
80#[cfg(test)]
81pub(crate) use registry::test_support;
82pub mod intercept;
83pub(crate) mod shared;
84pub mod startup_validation;
85pub mod step;
86pub mod template;
87pub mod transacted_segment;
88pub mod transacted_walk;
89
90#[cfg(feature = "export-internal-adapters")]
91pub mod route {
92    pub use crate::lifecycle::adapters::route_compiler::{
93        PipelineRuntimeCtx, RouteChannelService, TracerPipelineGating, compose_pipeline,
94        compose_pipeline_with_contracts, compose_pipeline_with_handler, compose_traced_pipeline,
95    };
96    pub use crate::lifecycle::adapters::route_types::Route;
97    pub use crate::lifecycle::adapters::step_compilers::CompiledStep;
98    pub use crate::lifecycle::application::route_definition::*;
99    pub use crate::lifecycle::domain::route::RouteSpec;
100}
101
102#[cfg(feature = "export-internal-adapters")]
103pub mod route_controller {
104    pub use crate::lifecycle::adapters::route_controller::*;
105    pub use crate::lifecycle::adapters::route_controller_trait::{
106        BindExposureAcks, enforce_bind_exposure_gate,
107    };
108}
109
110pub mod supervising_route_controller {
111    pub use crate::lifecycle::adapters::controller_actor::spawn_supervision_task;
112}
113
114pub mod reload_watcher {
115    pub use crate::hot_reload::adapters::reload_watcher::*;
116    pub use crate::hot_reload::application::FunctionReloadContext;
117    pub use crate::hot_reload::application::execute_reload_actions;
118    pub use crate::hot_reload::domain::ReloadAction;
119}
120
121pub use crate::hot_reload::adapters::ReloadWatcher;
122pub use crate::hot_reload::application::FunctionReloadContext;
123pub use crate::hot_reload::application::execute_reload_actions;
124pub use crate::hot_reload::domain::ReloadAction;
125#[cfg(feature = "export-internal-adapters")]
126pub use crate::idempotent::RedbIdempotentRepository;
127pub use crate::language_registry::LanguageRegistryError;
128pub use crate::lifecycle::adapters::controller_actor::RouteControllerHandle;
129pub use crate::lifecycle::adapters::controller_actor::spawn_controller_actor;
130pub use crate::lifecycle::adapters::controller_actor::spawn_supervision_task;
131#[cfg(feature = "export-internal-adapters")]
132pub use crate::lifecycle::adapters::exchange_uow::ExchangeUoWLayer;
133#[cfg(feature = "export-internal-adapters")]
134pub use crate::lifecycle::adapters::redb_journal::{
135    JournalDurability, JournalEntry, JournalInspectFilter, RedbJournalOptions,
136    RedbRuntimeEventJournal,
137};
138
139#[cfg(feature = "export-internal-adapters")]
140pub use crate::lifecycle::adapters::route_controller::DefaultRouteController;
141#[cfg(feature = "export-internal-adapters")]
142pub use crate::lifecycle::adapters::route_types::Route;
143#[cfg(feature = "export-internal-adapters")]
144pub use crate::lifecycle::adapters::{
145    InMemoryCommandDedup, InMemoryEventPublisher, InMemoryProjectionStore, InMemoryRouteRepository,
146    InMemoryRuntimeStore, RuntimeExecutionAdapter,
147};
148pub use crate::lifecycle::application::ports::{
149    CommandDedupPort, EventPublisherPort, InFlightCountResult, ProjectionStorePort,
150    RouteRepositoryPort, RouteStatusProjection, RuntimeEventJournalPort, RuntimeExecutionPort,
151    RuntimeUnitOfWorkPort,
152};
153pub use crate::lifecycle::application::runtime_bus::RuntimeBus;
154pub use crate::lifecycle::application::{BuilderStep, RouteDefinition};
155pub use crate::lifecycle::domain::{
156    RouteLifecycleCommand, RouteRuntimeAggregate, RouteRuntimeState, RuntimeEvent,
157};
158pub use crate::shared::components::domain::Registry;
159pub use crate::shared::components::domain::RegistryComponentContext;
160pub use crate::shared::observability::adapters::TracingProcessor;
161pub use crate::shared::observability::domain::{
162    DetailLevel, FileOutput, MetricsLeversConfig, OutputFormat, StdoutOutput, TracerConfig,
163    TracerOutputs,
164};
165pub use context::CamelContext;
166pub use language_registry::from_config as languages_from_config;
167pub use template::TemplateRegistry;
168
169// Re-export route controller types from camel-api (they live there to avoid cyclic dependencies).
170pub use camel_api::CamelError;
171pub use camel_api::{RouteAction, RouteController, RouteStatus};
172
173impl From<lifecycle::domain::DomainError> for CamelError {
174    fn from(e: lifecycle::domain::DomainError) -> Self {
175        CamelError::RouteError(e.to_string())
176    }
177}
178
179impl From<crate::language_registry::LanguageRegistryError> for CamelError {
180    fn from(e: crate::language_registry::LanguageRegistryError) -> Self {
181        CamelError::Config(e.to_string())
182    }
183}