pub struct RealtimeManager { /* private fields */ }Expand description
Manages WebSocket connections and SSE subscriptions.
Each event broadcast through RealtimeManager::broadcast is:
- Assigned a monotonically-increasing
seq_id. - Pushed into an in-memory ring buffer (capacity [
DEFAULT_MAX_BUFFERED_EVENTS]). - Sent over the tokio broadcast channel for live subscribers.
Clients that reconnect with a Last-Event-Id header can call
RealtimeManager::get_events_after to retrieve buffered events they missed.
Implementations§
Source§impl RealtimeManager
impl RealtimeManager
Sourcepub fn with_buffer_size(max_buffered_events: usize) -> Self
pub fn with_buffer_size(max_buffered_events: usize) -> Self
Create a realtime manager with a custom ring-buffer size.
Sourcepub fn broadcast(&self, event: RealtimeEvent)
pub fn broadcast(&self, event: RealtimeEvent)
Broadcast an event to all matching clients.
The event is stamped with a sequential seq_id, pushed into the ring
buffer, and sent over the broadcast channel.
Sourcepub fn get_events_after(&self, last_seq_id: u64) -> Vec<RealtimeEvent>
pub fn get_events_after(&self, last_seq_id: u64) -> Vec<RealtimeEvent>
Return all buffered events whose seq_id is strictly greater than
last_seq_id, in ascending order. Used to replay missed events for
reconnecting clients.
Sourcepub fn current_seq(&self) -> u64
pub fn current_seq(&self) -> u64
Return the current value of the sequence counter (next ID to be issued). Mainly useful for tests.
Sourcepub fn client_count(&self) -> usize
pub fn client_count(&self) -> usize
Get number of connected clients
Sourcepub fn subscribe(&self) -> Receiver<RealtimeEvent>
pub fn subscribe(&self) -> Receiver<RealtimeEvent>
Subscribe to live events
Sourcepub fn register_client(&self, id: String, filter: SubscriptionFilter)
pub fn register_client(&self, id: String, filter: SubscriptionFilter)
Register a new client
Sourcepub fn unregister_client(&self, id: &str)
pub fn unregister_client(&self, id: &str)
Unregister a client
Sourcepub fn get_client_filter(&self, id: &str) -> Option<SubscriptionFilter>
pub fn get_client_filter(&self, id: &str) -> Option<SubscriptionFilter>
Get client filter
Trait Implementations§
Source§impl Clone for RealtimeManager
impl Clone for RealtimeManager
Auto Trait Implementations§
impl Freeze for RealtimeManager
impl !RefUnwindSafe for RealtimeManager
impl Send for RealtimeManager
impl Sync for RealtimeManager
impl Unpin for RealtimeManager
impl UnsafeUnpin for RealtimeManager
impl !UnwindSafe for RealtimeManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more