allora_core/patterns/mod.rs
1//! Integration Patterns module: collection of Enterprise Integration Patterns (EIP) primitives.
2//!
3//! # Provided Patterns
4//! * `filter` – Conditional acceptance/rejection of an `Exchange` (`Filter`).
5//! * `content_router` – Content-based routing using predicates to select a downstream processor (`ContentBasedRouter`).
6//! * `splitter` – Split a single inbound message into multiple outbound messages (`Splitter`).
7//! * `aggregator` – Aggregate correlated messages until a completion condition is met (`Aggregator`).
8//! * `recipient_list` – Fan-out to a dynamic list of processors (`RecipientList`).
9//! * `correlation_initializer` – Ensure a `correlation_id` (and optional mirror header) early in a route.
10//!
11//! # Design Notes
12//! Patterns follow Enterprise Integration Pattern semantics adapted to idiomatic Rust:
13//! * Trait (`Processor`) keeps implementations lightweight.
14//! * Correlation handled lazily; use `CorrelationInitializer` or call `Exchange::correlation_id()`.
15//! * Each pattern lives in its own module with focused responsibilities.
16//!
17//! # Example: Filter and Aggregator Combined
18//! ```rust
19//! use allora_core::{route::Route , Exchange, Message};
20//! use allora_core::patterns::{aggregator::Aggregator, correlation_initializer::CorrelationInitializer, filter::Filter};
21//! let route = Route::new()
22//! .add(CorrelationInitializer::with_mirror("corr"))
23//! .add(Filter::new(|exchange: &Exchange| exchange.in_msg.body_text() == Some("keep")))
24//! .add(Aggregator::new("corr", 2))
25//! .build();
26//! let mut exchange = Exchange::new(Message::from_text("keep"));
27//! let rt = tokio::runtime::Runtime::new().unwrap();
28//! rt.block_on(async { route.run(&mut exchange).await.unwrap(); });
29//! assert!(exchange.out_msg.is_none());
30//! ```
31//!
32//! For detailed usage, see each submodule's own documentation and tests under `tests/`.
33pub mod aggregator;
34pub mod content_router;
35pub mod correlation_initializer;
36pub mod filter;
37pub mod recipient_list;
38pub mod splitter;