allora_runtime/
lib.rs

1//! Allora – Integration Patterns & Message Flow Building Blocks
2//!
3//! High-level, lightweight primitives for composing message-driven flows in Rust.
4//! Provides channels, messages, exchanges, simple filters/patterns, plus a facade
5//! (`Runtime`) for bootstrapping a runtime from a YAML configuration file.
6//!
7//! # Key Concepts
8//! * Message – immutable payload + headers
9//! * Exchange – mutable processing context (in/out message, headers, correlation)
10//! * Channel – in-memory endpoint for sending/receiving `Exchange` instances
11//! * Filter (pattern) – predicate over an `Exchange`
12//! * Runtime – collection of declared channels & filters built from a spec
13//!
14//! # Features
15//! Async-only architecture; HTTP adapters and serialization always enabled (no feature flags).
16//!
17//! # Crate Use
18//! * Programmatic: build channels/filters directly via builders
19//! * Declarative: provide `allora.yml` and use `Runtime::new().run()`
20//!
21//! # Minimal Programmatic Example
22//! ```rust
23//! use allora_core::{patterns::filter::Filter, Exchange, Message};
24//! let mut exchange = Exchange::new(Message::from_text("ping"));
25//! let f = Filter::new(|e: &Exchange| e.in_msg.body_text() == Some("ping"));
26//! assert!(f.accepts(&exchange));
27//! ```
28//!
29//! # Minimal YAML Channel Spec
30//! ```yaml
31//! version: 1
32//! channels:
33//!   - kind: direct
34//!     id: inbound
35//!   - kind: direct
36//!     id: outbound
37//! ```
38//! Build from file with:
39//! ```no_run
40//! # use allora_runtime::{Runtime, Channel};
41//! let rt = Runtime::new().with_config_file("./allora.yml").run()?;
42//! assert!(rt.channel_by_id("inbound").is_some());
43//! # Ok::<_, allora_runtime::Error>(())
44//! ```
45//!
46//! # Building Components Directly
47//! ```rust
48//! use allora_runtime::{build_channel_from_str, DslFormat, Channel};
49//! let raw = "version: 1\nchannel:\n  kind: direct\n  id: demo";
50//! let ch = build_channel_from_str(raw, DslFormat::Yaml).unwrap();
51//! assert_eq!(ch.id(), "demo");
52//! ```
53//!
54//! # Errors
55//! All builder and facade operations surface failures via `Error`.
56//! Use `Result<T, Error>` and propagate with `?`.
57//!
58//! # License
59//! MIT OR Apache-2.0.
60//!
61//! # Stability & Versioning
62//! * Parsers enforce `version`.
63//! * New versions add new parser modules.
64
65pub mod dsl; // new multi-format DSL facade (yaml/json/xml)
66pub mod runtime;
67pub mod service_activator_processor;
68pub mod spec; // new specification-based builders replacing DSL façade gradually
69pub use adapter::{
70    ensure_correlation, Adapter, InboundAdapter, OutboundAdapter, OutboundDispatchResult,
71};
72pub use allora_core::channel;
73pub use allora_core::endpoint;
74pub use allora_core::error;
75pub use allora_core::logging;
76pub use allora_core::message;
77pub use allora_core::patterns;
78pub use allora_core::processor;
79pub use allora_core::route;
80pub use allora_core::service;
81// Channel abstractions
82pub use allora_core::Filter;
83pub use allora_core::Route;
84pub use allora_core::{Endpoint, EndpointBuilder, EndpointSource, InMemoryEndpoint};
85
86// Top-level HTTP re-exports (behind the `http` feature)
87pub use allora_http::{
88    HttpInboundAdapter,
89    HttpInboundBuilder,
90    HttpOutboundAdapter,
91    HttpOutboundAdapterBuilder,
92    Mep,
93    InboundHttpExt,
94    OutboundHttpExt,
95};
96pub use channel::{
97    Channel, ChannelRef, CorrelationSupport, DirectChannel, PollableChannel, QueueChannel,
98    SubscribableChannel,
99};
100pub use dsl::runtime::AlloraRuntime;
101pub use dsl::{
102    build, build_channel, build_channel_from_str, build_filter, build_service, DslFormat,
103};
104pub use error::{Error, Result};
105pub use message::{Exchange, Message, Payload};
106pub use processor::{BoxedProcessor, ClosureProcessor, Processor};
107pub use runtime::Runtime;
108pub use service::{Service, ServiceActivator};
109
110#[derive(Clone)]
111pub struct ServiceDescriptor {
112    pub name: &'static str,
113    pub constructor: fn() -> Arc<dyn Service>,
114}
115inventory::collect!(ServiceDescriptor);
116
117pub fn all_service_descriptors() -> Vec<&'static ServiceDescriptor> {
118    let mut v = Vec::new();
119    for d in inventory::iter::<ServiceDescriptor> {
120        v.push(d);
121    }
122    v
123}
124
125pub mod adapter {
126    pub use allora_core::adapter::{
127        ensure_correlation,
128        BaseAdapter,
129        InboundAdapter,
130        OutboundAdapter,
131        OutboundDispatchResult,
132        Adapter,
133        InboundStage,
134        OutboundStage,
135    };
136    pub use allora_http::{
137        HttpInboundAdapter,
138        HttpInboundBuilder,
139        HttpOutboundAdapter,
140        HttpOutboundAdapterBuilder,
141        Mep,
142        InboundHttpExt,
143        OutboundHttpExt,
144    };
145}
146
147pub use inventory; // re-export for macro usage allora::inventory::submit!
148
149use std::sync::Arc;