Skip to main content

a3s_event/
lib.rs

1//! # a3s-event
2//!
3//! Pluggable event subscription, dispatch, and persistence for the A3S ecosystem.
4//!
5//! ## Overview
6//!
7//! `a3s-event` provides a provider-agnostic API for publishing, subscribing to,
8//! and persisting events. Swap backends (NATS, in-memory, Redis, Kafka, etc.)
9//! without changing application code.
10//!
11//! ## Quick Start
12//!
13//! ```rust
14//! use a3s_event::{EventBus, Event};
15//! use a3s_event::provider::memory::MemoryProvider;
16//!
17//! # async fn example() -> a3s_event::Result<()> {
18//! // Create an event bus with the in-memory provider
19//! let bus = EventBus::new(MemoryProvider::default());
20//!
21//! // Publish an event
22//! let event = bus.publish(
23//!     "market",
24//!     "forex.usd_cny",
25//!     "USD/CNY broke through 7.35",
26//!     "reuters",
27//!     serde_json::json!({"rate": 7.3521}),
28//! ).await?;
29//!
30//! println!("Published: {}", event.id);
31//! # Ok(())
32//! # }
33//! ```
34//!
35//! ## Providers
36//!
37//! - **memory** — In-memory provider for testing and single-process use
38//! - **nats** — NATS JetStream for distributed, persistent event streaming
39//!
40//! ## Architecture
41//!
42//! - **EventProvider** trait — core abstraction all backends implement
43//! - **EventBus** — high-level API with subscription management
44//! - **Subscription** trait — async event stream from any provider
45//! - **Event** — provider-agnostic message envelope
46
47#[cfg(feature = "routing")]
48pub mod broker;
49#[cfg(feature = "cloudevents")]
50pub mod cloudevents;
51#[cfg(feature = "encryption")]
52pub mod crypto;
53pub mod dlq;
54pub mod error;
55pub mod metrics;
56pub mod provider;
57pub mod schema;
58#[cfg(feature = "routing")]
59pub mod sink;
60#[cfg(feature = "routing")]
61pub mod source;
62pub mod state;
63pub mod store;
64pub mod subject;
65pub mod types;
66
67// Re-export core types
68#[cfg(feature = "routing")]
69pub use broker::{Broker, RouteResult, Trigger, TriggerFilter};
70#[cfg(feature = "cloudevents")]
71pub use cloudevents::CloudEvent;
72#[cfg(feature = "encryption")]
73pub use crypto::{Aes256GcmEncryptor, EncryptedPayload, EventEncryptor};
74pub use dlq::{DeadLetterEvent, DlqHandler, MemoryDlqHandler};
75#[cfg(feature = "routing")]
76pub use dlq::SinkDlqHandler;
77pub use error::{EventError, Result};
78pub use metrics::{EventMetrics, MetricsSnapshot};
79pub use provider::{EventProvider, PendingEvent, ProviderInfo, Subscription};
80pub use schema::{Compatibility, EventSchema, MemorySchemaRegistry, SchemaRegistry};
81#[cfg(feature = "routing")]
82pub use sink::{CollectorSink, EventSink, FailingSink, InProcessSink, LogSink, TopicSink};
83#[cfg(feature = "routing")]
84pub use source::{CronSource, EventSource};
85pub use state::{FileStateStore, MemoryStateStore, StateStore};
86pub use store::EventBus;
87pub use types::{
88    DeliverPolicy, Event, EventCounts, PublishOptions, ReceivedEvent, SubscribeOptions,
89    SubscriptionFilter,
90};
91
92// Re-export providers for convenience
93pub use provider::memory::{MemoryConfig, MemoryProvider};
94#[cfg(feature = "nats")]
95pub use provider::nats::{NatsClient, NatsConfig, NatsProvider, NatsSubscription, StorageType};