nstreams-core 0.2.2

Generic versioned event stream handler with history replay
Documentation
//! Generic versioned event stream handler with history replay.
//!
//! Events are namespaced: the namespace determines queue/stream names,
//! backend storage, and the shape of the event payload.

pub mod error;
pub mod event;
pub mod filter;
pub mod handler;
pub mod namespace;
pub mod publisher;
pub mod request_id;
pub mod store;
pub mod stream;
pub mod subscription;
pub mod version;
pub mod worker;

#[doc(hidden)]
pub mod testing;

pub use error::{Error, Result};
pub use event::{DeliveredEvent, EventCodec, StreamEvent, StreamEventEnvelope};
pub use filter::{StreamFilter, SubscribeRequest};
pub use request_id::{new_request_id, REQUEST_ID_PREFIX};
pub use handler::NStreamsHandler;
pub use namespace::Namespace;
pub use publisher::EventPublisher;
pub use store::EventStore;
pub use stream::{ReadStreamBackend, WriteQueueBackend};
pub use subscription::Subscription;
pub use version::VersionedDelivery;
pub use worker::StreamWorker;

/// Maximum history items retained in a read stream.
///
/// Derived from six months of five-minute candles:
/// `5 * 12 * 24 * 183 = 263_520`.
pub const MAX_STREAM_HISTORY_ITEMS: u64 = 263_520;

/// RabbitMQ stream max-age for read streams (six months).
pub const STREAM_MAX_AGE: &str = "183D";

/// Default assumed maximum serialized event size in bytes when sizing streams.
pub const DEFAULT_MAX_EVENT_BYTES: u64 = 4_096;

/// Compute the byte capacity for a read stream given an estimated event size.
pub fn stream_max_length_bytes(max_event_bytes: u64) -> u64 {
    max_event_bytes.saturating_mul(MAX_STREAM_HISTORY_ITEMS)
}