pub struct CorrelationInitializer { /* private fields */ }Expand description
A convenience processor that ensures a correlation id is present on the inbound message and (optionally) mirrors it to a configurable header name for legacy compatibility.
This is useful to place at the start of a Route so downstream processors
(splitters, aggregators, recipient lists, request/reply patterns) can assume
that a stable correlation_id header exists. It reduces boilerplate and the
chance of forgetting to set one, especially in heterogeneous pipelines.
§Behavior
- If
correlation_idheader exists, it is left untouched. - Otherwise a new UUID v4 is generated and stored under
correlation_id. - If
mirror_headeris set, that header key is also set to the same value.
§Example
use allora_core::{patterns::correlation_initializer::CorrelationInitializer, processor::ClosureProcessor, route::Route, Exchange, Message};
let route = Route::new()
.add(CorrelationInitializer::default())
.add(ClosureProcessor::new(|exchange| { exchange.out_msg = Some(Message::from_text("done")); Ok(()) }))
.build();
let mut exchange = Exchange::new(Message::from_text("hi"));
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async { route.run(&mut exchange).await.unwrap(); });
assert!(exchange.in_msg.header("correlation_id").is_some());Implementations§
Source§impl CorrelationInitializer
impl CorrelationInitializer
Sourcepub fn with_mirror<H>(header: H) -> CorrelationInitializer
pub fn with_mirror<H>(header: H) -> CorrelationInitializer
Create with optional mirror header (e.g. legacy systems expect corr).
Trait Implementations§
Source§impl Clone for CorrelationInitializer
impl Clone for CorrelationInitializer
Source§fn clone(&self) -> CorrelationInitializer
fn clone(&self) -> CorrelationInitializer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CorrelationInitializer
impl Debug for CorrelationInitializer
Source§impl Default for CorrelationInitializer
impl Default for CorrelationInitializer
Source§fn default() -> CorrelationInitializer
fn default() -> CorrelationInitializer
Returns the “default value” for a type. Read more
Source§impl Processor for CorrelationInitializer
impl Processor for CorrelationInitializer
Auto Trait Implementations§
impl Freeze for CorrelationInitializer
impl RefUnwindSafe for CorrelationInitializer
impl Send for CorrelationInitializer
impl Sync for CorrelationInitializer
impl Unpin for CorrelationInitializer
impl UnwindSafe for CorrelationInitializer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more