pub struct SubscriptionManager { /* private fields */ }Expand description
Manages active subscriptions and event routing.
The SubscriptionManager is the central hub for:
- Tracking active subscriptions per connection
- Receiving events from database listeners
- Matching events to subscriptions
- Broadcasting to transport adapters
Implementations§
Source§impl SubscriptionManager
impl SubscriptionManager
Sourcepub fn new(schema: Arc<CompiledSchema>) -> Self
pub fn new(schema: Arc<CompiledSchema>) -> Self
Create a new subscription manager.
§Arguments
schema- Compiled schema containing subscription definitionschannel_capacity- Broadcast channel capacity (default: 1024)
Sourcepub fn with_capacity(
schema: Arc<CompiledSchema>,
channel_capacity: usize,
) -> Self
pub fn with_capacity( schema: Arc<CompiledSchema>, channel_capacity: usize, ) -> Self
Create a new subscription manager with custom channel capacity.
Sourcepub fn receiver(&self) -> Receiver<SubscriptionPayload>
pub fn receiver(&self) -> Receiver<SubscriptionPayload>
Get a receiver for subscription payloads.
Transport adapters use this to receive events for delivery.
Sourcepub fn subscribe(
&self,
subscription_name: &str,
user_context: Value,
variables: Value,
connection_id: &str,
) -> Result<SubscriptionId, SubscriptionError>
pub fn subscribe( &self, subscription_name: &str, user_context: Value, variables: Value, connection_id: &str, ) -> Result<SubscriptionId, SubscriptionError>
Subscribe to a subscription type.
§Arguments
subscription_name- Name of the subscription typeuser_context- User authentication/authorization contextvariables- Runtime variables from clientconnection_id- Client connection identifier
§Errors
Returns error if subscription not found or user not authorized.
Sourcepub fn subscribe_with_rls(
&self,
subscription_name: &str,
user_context: Value,
variables: Value,
connection_id: &str,
rls_conditions: Vec<(String, Value)>,
) -> Result<SubscriptionId, SubscriptionError>
pub fn subscribe_with_rls( &self, subscription_name: &str, user_context: Value, variables: Value, connection_id: &str, rls_conditions: Vec<(String, Value)>, ) -> Result<SubscriptionId, SubscriptionError>
Subscribe with pre-evaluated RLS conditions for event-level filtering.
The caller should evaluate the RLS policy at subscribe time and pass
the resulting conditions (via extract_rls_conditions).
During event delivery, each condition is checked against the event data:
the event is only delivered if every condition matches.
§Errors
Returns error if subscription not found or connection limit exceeded.
Sourcepub fn unsubscribe(&self, id: SubscriptionId) -> Result<(), SubscriptionError>
pub fn unsubscribe(&self, id: SubscriptionId) -> Result<(), SubscriptionError>
Sourcepub fn unsubscribe_connection(&self, connection_id: &str)
pub fn unsubscribe_connection(&self, connection_id: &str)
Unsubscribe all subscriptions for a connection.
Called when a client disconnects.
§Concurrency note
A concurrent subscribe call that runs between the DashMap entry removal and the
per-subscription cleanup loop would create a new connection entry that is not cleaned
up by this call. A second-pass removal after the first loop closes this window for
all but the most extreme concurrent races. Any subscription that slips through is
benign: it will receive events until the broadcast receiver is dropped (which happens
on disconnect), and will be removed on the next disconnect or subscription-not-found
event for that ID.
Sourcepub fn get_subscription(&self, id: SubscriptionId) -> Option<ActiveSubscription>
pub fn get_subscription(&self, id: SubscriptionId) -> Option<ActiveSubscription>
Get an active subscription by ID.
Sourcepub fn get_connection_subscriptions(
&self,
connection_id: &str,
) -> Vec<ActiveSubscription>
pub fn get_connection_subscriptions( &self, connection_id: &str, ) -> Vec<ActiveSubscription>
Get all active subscriptions for a connection.
Sourcepub fn subscription_count(&self) -> usize
pub fn subscription_count(&self) -> usize
Get total number of active subscriptions.
Sourcepub fn connection_count(&self) -> usize
pub fn connection_count(&self) -> usize
Get number of active connections with subscriptions.
Sourcepub fn publish_event(&self, event: SubscriptionEvent) -> usize
pub fn publish_event(&self, event: SubscriptionEvent) -> usize
Publish an event to matching subscriptions.
This is called by the database listener when an event is received. The event is matched against all active subscriptions and delivered to matching ones.
§Arguments
event- The database event to publish
§Returns
Number of subscriptions that matched the event.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SubscriptionManager
impl !RefUnwindSafe for SubscriptionManager
impl Send for SubscriptionManager
impl Sync for SubscriptionManager
impl Unpin for SubscriptionManager
impl UnsafeUnpin for SubscriptionManager
impl UnwindSafe for SubscriptionManager
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> 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