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
47pub mod broker;
48pub mod cloudevents;
49pub mod crypto;
50pub mod dlq;
51pub mod error;
52pub mod metrics;
53pub mod provider;
54pub mod scaling;
55pub mod schema;
56pub mod sink;
57pub mod source;
58pub mod state;
59pub mod store;
60pub mod subject;
61pub mod types;
62
63// Re-export core types
64pub use broker::{Broker, RouteResult, Trigger, TriggerFilter};
65pub use cloudevents::CloudEvent;
66pub use crypto::{Aes256GcmEncryptor, EncryptedPayload, EventEncryptor};
67pub use dlq::{DeadLetterEvent, DlqHandler, MemoryDlqHandler, SinkDlqHandler};
68pub use error::{EventError, Result};
69pub use metrics::{EventMetrics, MetricsSnapshot};
70pub use provider::{EventProvider, PendingEvent, ProviderInfo, Subscription};
71pub use scaling::{
72 InstanceHealthPayload, InstanceReadyPayload, InstanceStoppedPayload, ScaleDownPayload,
73 ScaleUpPayload, ScalingEvent,
74};
75pub use schema::{Compatibility, EventSchema, MemorySchemaRegistry, SchemaRegistry};
76pub use sink::{CollectorSink, EventSink, FailingSink, InProcessSink, LogSink, TopicSink};
77pub use source::{CronSource, EventSource};
78pub use state::{FileStateStore, MemoryStateStore, StateStore};
79pub use store::EventBus;
80pub use types::{
81 DeliverPolicy, Event, EventCounts, PublishOptions, ReceivedEvent, SubscribeOptions,
82 SubscriptionFilter,
83};
84
85// Re-export providers for convenience
86pub use provider::memory::{MemoryConfig, MemoryProvider};
87pub use provider::nats::{NatsClient, NatsConfig, NatsProvider, NatsSubscription, StorageType};