Skip to main content

nstreams_core/
lib.rs

1//! Generic versioned event stream handler with history replay.
2//!
3//! Events are namespaced: the namespace determines queue/stream names,
4//! backend storage, and the shape of the event payload.
5
6pub mod error;
7pub mod event;
8pub mod filter;
9pub mod handler;
10pub mod namespace;
11pub mod publisher;
12pub mod request_id;
13pub mod store;
14pub mod stream;
15pub mod subscription;
16pub mod version;
17pub mod worker;
18
19#[doc(hidden)]
20pub mod testing;
21
22pub use error::{Error, Result};
23pub use event::{DeliveredEvent, EventCodec, StreamEvent, StreamEventEnvelope};
24pub use filter::{StreamFilter, SubscribeRequest};
25pub use request_id::{new_request_id, REQUEST_ID_PREFIX};
26pub use handler::NStreamsHandler;
27pub use namespace::Namespace;
28pub use publisher::EventPublisher;
29pub use store::EventStore;
30pub use stream::{ReadStreamBackend, WriteQueueBackend};
31pub use subscription::Subscription;
32pub use version::VersionedDelivery;
33pub use worker::StreamWorker;
34
35/// Maximum history items retained in a read stream.
36///
37/// Derived from six months of five-minute candles:
38/// `5 * 12 * 24 * 183 = 263_520`.
39pub const MAX_STREAM_HISTORY_ITEMS: u64 = 263_520;
40
41/// RabbitMQ stream max-age for read streams (six months).
42pub const STREAM_MAX_AGE: &str = "183D";
43
44/// Default assumed maximum serialized event size in bytes when sizing streams.
45pub const DEFAULT_MAX_EVENT_BYTES: u64 = 4_096;
46
47/// Compute the byte capacity for a read stream given an estimated event size.
48pub fn stream_max_length_bytes(max_event_bytes: u64) -> u64 {
49    max_event_bytes.saturating_mul(MAX_STREAM_HISTORY_ITEMS)
50}