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, HttpInboundBuilder, HttpOutboundAdapter, HttpOutboundAdapterBuilder,
89 InboundHttpExt, Mep, OutboundHttpExt,
90};
91pub use channel::{
92 Channel, ChannelRef, CorrelationSupport, DirectChannel, PollableChannel, QueueChannel,
93 SubscribableChannel,
94};
95pub use dsl::runtime::{AlloraRuntime, FilterActivation, HttpOutboundAdapterActivation};
96pub use dsl::{
97 build, build_channel, build_channel_from_str, build_filter, build_service, DslFormat,
98};
99pub use error::{Error, Result};
100pub use message::{Exchange, Message, Payload};
101pub use processor::{BoxedProcessor, ClosureProcessor, Processor};
102pub use runtime::Runtime;
103pub use service::{Service, ServiceActivator};
104
105#[derive(Clone)]
106pub struct ServiceDescriptor {
107 pub name: &'static str,
108 pub constructor: fn() -> Arc<dyn Service>,
109}
110inventory::collect!(ServiceDescriptor);
111
112pub fn all_service_descriptors() -> Vec<&'static ServiceDescriptor> {
113 let mut v = Vec::new();
114 for d in inventory::iter::<ServiceDescriptor> {
115 v.push(d);
116 }
117 v
118}
119
120pub mod adapter {
121 pub use allora_core::adapter::{
122 ensure_correlation, Adapter, BaseAdapter, InboundAdapter, InboundStage, OutboundAdapter,
123 OutboundDispatchResult, OutboundStage,
124 };
125 pub use allora_http::{
126 HttpInboundAdapter, HttpInboundBuilder, HttpOutboundAdapter, HttpOutboundAdapterBuilder,
127 InboundHttpExt, Mep, OutboundHttpExt,
128 };
129}
130
131pub use inventory; // re-export for macro usage allora::inventory::submit!
132
133use std::sync::Arc;