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