pub struct EventStore { /* private fields */ }Expand description
Thread-safe event store for SSE resumability.
Stores events per stream with automatic expiration and size limits. Use this to enable clients to resume SSE streams after disconnection.
§Thread Safety
The EventStore uses RwLock internally and is safe for concurrent
access from multiple threads.
Implementations§
Source§impl EventStore
impl EventStore
Sourcepub fn new() -> EventStore
pub fn new() -> EventStore
Creates a new event store with default configuration.
Sourcepub fn with_config(config: EventStoreConfig) -> EventStore
pub fn with_config(config: EventStoreConfig) -> EventStore
Creates a new event store with custom configuration.
Sourcepub fn config(&self) -> &EventStoreConfig
pub fn config(&self) -> &EventStoreConfig
Returns the configuration.
Sourcepub fn store_priming_event(&self, stream_id: &str) -> String
pub fn store_priming_event(&self, stream_id: &str) -> String
Stores a priming event (empty data) for SSE initialization.
Per SSE spec, servers should send an event with just an ID to prime
the client’s Last-Event-ID tracking.
Sourcepub fn get_events_after(
&self,
stream_id: &str,
after_id: Option<&str>,
) -> Vec<EventEntry>
pub fn get_events_after( &self, stream_id: &str, after_id: Option<&str>, ) -> Vec<EventEntry>
Sourcepub fn replay_events_after<F>(
&self,
last_event_id: &str,
callback: F,
) -> Option<String>where
F: FnMut(&EventEntry),
pub fn replay_events_after<F>(
&self,
last_event_id: &str,
callback: F,
) -> Option<String>where
F: FnMut(&EventEntry),
Replays events after a specific event ID using a callback.
This is the primary method for SSE resumption. When a client reconnects
with a Last-Event-ID, use this to replay missed events.
§Arguments
last_event_id- The client’s last received event IDcallback- Called for each event to replay
§Returns
The stream ID if the event was found, None otherwise.
Sourcepub fn find_stream_for_event(&self, event_id: &str) -> Option<String>
pub fn find_stream_for_event(&self, event_id: &str) -> Option<String>
Looks up the stream ID for a given event ID.
§Returns
The stream ID if the event exists, None otherwise.
Sourcepub fn clear_stream(&self, stream_id: &str)
pub fn clear_stream(&self, stream_id: &str)
Removes all events for a stream.
Call this when a session ends to free memory.
Sourcepub fn cleanup_expired(&self)
pub fn cleanup_expired(&self)
Removes all expired events across all streams.
This is called automatically during operations, but you can call it manually for cleanup.
Sourcepub fn stream_count(&self) -> usize
pub fn stream_count(&self) -> usize
Returns the number of streams currently stored.
Sourcepub fn event_count(&self) -> usize
pub fn event_count(&self) -> usize
Returns the total number of events across all streams.
Sourcepub fn stats(&self) -> EventStoreStats
pub fn stats(&self) -> EventStoreStats
Returns statistics about the event store.