pub struct MessageBus { /* private fields */ }Expand description
Subscriber/cursor message bus with idempotent send and consume.
Implementations§
Source§impl MessageBus
impl MessageBus
Sourcepub const fn with_maxlen(maxlen: usize) -> Self
pub const fn with_maxlen(maxlen: usize) -> Self
Create an empty message bus with a bounded retention length.
Sourcepub fn subscribe(&mut self, agent_id: impl Into<String>)
pub fn subscribe(&mut self, agent_id: impl Into<String>)
Register a subscriber. New subscribers start at the current tail.
Sourcepub fn unsubscribe(&mut self, agent_id: &str)
pub fn unsubscribe(&mut self, agent_id: &str)
Remove a subscriber and its cursor state.
Sourcepub fn is_subscribed(&self, agent_id: &str) -> bool
pub fn is_subscribed(&self, agent_id: &str) -> bool
Return whether the given agent currently has a subscriber cursor.
Sourcepub fn send(&mut self, message: BusMessage) -> BusMessage
pub fn send(&mut self, message: BusMessage) -> BusMessage
Send a message idempotently.
Sourcepub fn consume(&mut self, agent_id: impl Into<String>) -> Vec<BusMessage>
pub fn consume(&mut self, agent_id: impl Into<String>) -> Vec<BusMessage>
Consume unread messages for a subscriber.
Sourcepub fn consume_matching(
&mut self,
agent_id: impl Into<String>,
predicate: impl Fn(&BusMessage) -> bool,
) -> Vec<BusMessage>
pub fn consume_matching( &mut self, agent_id: impl Into<String>, predicate: impl Fn(&BusMessage) -> bool, ) -> Vec<BusMessage>
Consume unread messages matching a predicate while preserving other pending messages.
Sourcepub fn peek(&self, agent_id: &str) -> Vec<BusMessage>
pub fn peek(&self, agent_id: &str) -> Vec<BusMessage>
Return unread messages without advancing the cursor.
Sourcepub fn mark_consumed(
&mut self,
agent_id: impl Into<String>,
message_ids: &BTreeSet<String>,
) -> usize
pub fn mark_consumed( &mut self, agent_id: impl Into<String>, message_ids: &BTreeSet<String>, ) -> usize
Mark specific unread messages as consumed for a subscriber.
Returns the number of currently unread messages that were marked consumed.
Sourcepub fn has_pending(&self, agent_id: &str) -> bool
pub fn has_pending(&self, agent_id: &str) -> bool
Return whether there are pending messages for one subscriber.
Sourcepub fn has_topic(&self, topic: &str) -> bool
pub fn has_topic(&self, topic: &str) -> bool
Return whether any queued message has the provided topic.
Sourcepub fn subscriber_count(&self) -> usize
pub fn subscriber_count(&self) -> usize
Return number of subscribers.
Sourcepub fn messages(&self) -> &[BusMessage]
pub fn messages(&self) -> &[BusMessage]
Return retained messages.
Trait Implementations§
Source§impl Clone for MessageBus
impl Clone for MessageBus
Source§fn clone(&self) -> MessageBus
fn clone(&self) -> MessageBus
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more