Struct SubscriberManager
pub struct SubscriberManager {
subscribers: TopicFilterMap<SubscriberSender>,
close_tx: Option<Sender<()>>,
channel_capacity: usize,
}Fields§
§subscribers: TopicFilterMap<SubscriberSender>§close_tx: Option<Sender<()>>§channel_capacity: usizeImplementations§
§impl SubscriberManager
impl SubscriberManager
pub const fn new(capacity: usize) -> Self
pub const fn new(capacity: usize) -> Self
Creates a new SubscriberManager instance with the provided
capacity.
The capacity parameter sets the capacity of the broadcast channels
used to distribute messages to subscribers. If capacity is 0, it
is set to 1. If capacity is between 0 and usize::MAX / 2, it is
used as is. If capacity is between usize::MAX / 2 + 1 and
usize::MAX, it is set to usize::MAX / 2.
pub fn with_close_tx(self, close_tx: Sender<()>) -> Self
pub fn with_close_tx(self, close_tx: Sender<()>) -> Self
Sets the close_tx channel sender for this subscriber manager.
fn subscribe_inner( &mut self, topic_filter: &TopicFilter<str>, qos: QoS, ) -> &mut SubscriberSender
pub fn subscribe(
&mut self,
topic_filter: &TopicFilter<str>,
qos: QoS,
) -> StdResult<Subscriber, Subscriber>
pub fn subscribe( &mut self, topic_filter: &TopicFilter<str>, qos: QoS, ) -> StdResult<Subscriber, Subscriber>
Subscribes to the given topic filter.
Returns Ok if the subscription needs to be created, or Err if the
subscription already exists and is active.
If the caller receives Ok, it’s their responsibility to actually send
the subscription request to the broker and to confirm the subscription
to the manager.
pub fn subscribe_many(
&mut self,
topic_filters: impl IntoIterator<Item = impl AsRef<str>>,
qos: QoS,
) -> (Subscriber, Vec<TopicFilter<Box<str>>>)
pub fn subscribe_many( &mut self, topic_filters: impl IntoIterator<Item = impl AsRef<str>>, qos: QoS, ) -> (Subscriber, Vec<TopicFilter<Box<str>>>)
Subscribes to multiple topic filters at once.
Returns a tuple containing the subscriber and a list of topic filters that are yet to be subscribed. It’s the caller’s responsibility to subscribe to these filters and confirm the subscription to the manager.
pub fn route_publish(&mut self, publish: &Publish)
pub fn route_publish(&mut self, publish: &Publish)
Routes a publish message to all matching subscribers.
pub fn broadcast_error(&mut self, error: Error)
pub fn broadcast_error(&mut self, error: Error)
Sends the given error to all subscribers.
pub fn mark_all_subscriptions_as_pending(&mut self)
pub fn mark_all_subscriptions_as_pending(&mut self)
Marks all subscriptions as pending.
pub fn confirm_subscribe(&mut self, topic_filter: &TopicFilter<str>)
pub fn confirm_subscribe(&mut self, topic_filter: &TopicFilter<str>)
Confirms that a given topic filter has been subscribed to.
pub fn confirm_unsubscribe(&mut self, topic_filter: &TopicFilter<str>)
pub fn confirm_unsubscribe(&mut self, topic_filter: &TopicFilter<str>)
Confirms that a given topic filter has been unsubscribed.
At this point we can fully remove the subscriber from the manager.
pub fn schedule_unsubscribe(&mut self, topic_filter: &TopicFilter<str>)
pub fn schedule_unsubscribe(&mut self, topic_filter: &TopicFilter<str>)
Schedules the unsubscription of the given topic.
pub fn schedule_unsubscribe_many<It>(&mut self, topic_filters: It)
pub fn schedule_unsubscribe_many<It>(&mut self, topic_filters: It)
Schedules the unsubscription of the given topics.
pub fn perform_pending_operations(&mut self, client: &AsyncClient)
pub fn perform_pending_operations(&mut self, client: &AsyncClient)
Performs any pending subscribe or unsubscribe operations on the client.
The function tries to queue as many operations as possible into the client, stopping only once the client starts rejecting operations (most likely because the queue is full). All queued operations are then confirmed, so that the next time this function is called, only new or remaining pending operations will be processed.
This should only be called if the client is connected.