pub struct Exchange {
pub input: Message,
pub output: Option<Message>,
pub properties: HashMap<String, Value>,
pub extensions: HashMap<String, Arc<dyn Any + Send + Sync>>,
pub error: Option<CamelError>,
pub pattern: ExchangePattern,
pub correlation_id: String,
pub otel_context: Context,
}Expand description
An Exchange represents a message being routed through the framework.
It contains the input message, an optional output message, properties for passing data between processors, and error state.
Fields§
§input: MessageThe input (incoming) message.
output: Option<Message>The output (response) message, populated for InOut patterns.
properties: HashMap<String, Value>Exchange-scoped properties for passing data between processors.
extensions: HashMap<String, Arc<dyn Any + Send + Sync>>Non-serializable extension values (e.g., channel senders).
Stored as Arc<dyn Any + Send + Sync> so cloning is cheap (ref-count bump).
error: Option<CamelError>Error state, if processing failed.
pattern: ExchangePatternThe exchange pattern.
correlation_id: StringUnique correlation ID for distributed tracing.
otel_context: ContextOpenTelemetry context for distributed tracing propagation. Carries the active span context between processing steps. Defaults to an empty context (noop span) if OTel is not active.
Implementations§
Source§impl Exchange
impl Exchange
Sourcepub fn new_in_out(input: Message) -> Self
pub fn new_in_out(input: Message) -> Self
Create a new exchange with the InOut pattern.
Sourcepub fn correlation_id(&self) -> &str
pub fn correlation_id(&self) -> &str
Get the correlation ID for this exchange.
Sourcepub fn set_property(&mut self, key: impl Into<String>, value: impl Into<Value>)
pub fn set_property(&mut self, key: impl Into<String>, value: impl Into<Value>)
Set a property value.
Sourcepub fn set_error(&mut self, error: CamelError)
pub fn set_error(&mut self, error: CamelError)
Set an error on this exchange.
Automatically populates exchange properties with error context so that all languages can access error information via their property mechanisms:
CamelExceptionMessage— the error’s Display stringCamelExceptionKind— the error variant name (viaCamelError::classify())CamelExceptionCaught— alias for Java Camel parity
Sourcepub fn clear_error(&mut self)
pub fn clear_error(&mut self)
Clear the error and remove all exception properties.
Called after handled:true in on_exception steps to prevent stale
error state from leaking into subsequent processing.
Sourcepub fn handle_error(&mut self)
pub fn handle_error(&mut self)
Mark the exception as handled and clear the error.
Sets CamelExceptionHandled = true then calls clear_error().
This matches Java Camel’s Exchange.EXCEPTION_HANDLED semantics.
Sourcepub fn set_extension(
&mut self,
key: impl Into<String>,
value: Arc<dyn Any + Send + Sync>,
)
pub fn set_extension( &mut self, key: impl Into<String>, value: Arc<dyn Any + Send + Sync>, )
Store a non-serializable extension value (e.g. a channel sender).
Sourcepub fn get_extension<T: Any>(&self, key: &str) -> Option<&T>
pub fn get_extension<T: Any>(&self, key: &str) -> Option<&T>
Retrieve a typed extension value. Returns None if the key is absent
or the stored value is not of type T.
Sourcepub fn body_as<T: FromBody>(&self) -> Result<T, CamelError>
pub fn body_as<T: FromBody>(&self) -> Result<T, CamelError>
Deserialize the body into type T.
Uses built-in conversions for String, Vec<u8>, bytes::Bytes, and
serde_json::Value. For custom types, implement FromBody or use
[impl_from_body_via_serde!].
§Example
let text: String = exchange.body_as::<String>()?;
let raw: Vec<u8> = exchange.body_as::<Vec<u8>>()?;