pub struct MessageBus { /* private fields */ }Expand description
An in-process publish/subscribe message bus.
Supports topic-based subscriptions where subscribers can listen for specific message types. Messages published to the bus are stored in per-subscriber mailboxes for retrieval.
Implementations§
Source§impl MessageBus
impl MessageBus
Sourcepub fn with_mailbox_size(max_size: usize) -> Self
pub fn with_mailbox_size(max_size: usize) -> Self
Creates a new message bus with a custom mailbox size limit.
Sourcepub fn subscribe(
&mut self,
subscriber_id: Uuid,
types: Vec<MessageType>,
) -> SubscriptionId
pub fn subscribe( &mut self, subscriber_id: Uuid, types: Vec<MessageType>, ) -> SubscriptionId
Subscribes to specific message types.
Returns a SubscriptionId that can be used to receive messages
or unsubscribe later.
Sourcepub fn unsubscribe(&mut self, sub_id: &SubscriptionId) -> bool
pub fn unsubscribe(&mut self, sub_id: &SubscriptionId) -> bool
Unsubscribes and removes the subscription.
Sourcepub fn publish(&mut self, message: BusMessage) -> usize
pub fn publish(&mut self, message: BusMessage) -> usize
Publishes a message to all matching subscribers.
Returns the number of subscribers the message was delivered to.
Sourcepub fn receive(&mut self, sub_id: &SubscriptionId) -> Vec<BusMessage>
pub fn receive(&mut self, sub_id: &SubscriptionId) -> Vec<BusMessage>
Receives all pending messages for a subscription.
Drains the mailbox, returning all messages.
Sourcepub fn pending_count(&self, sub_id: &SubscriptionId) -> usize
pub fn pending_count(&self, sub_id: &SubscriptionId) -> usize
Returns the number of pending messages for a subscription.
Sourcepub fn subscription_count(&self) -> usize
pub fn subscription_count(&self) -> usize
Returns the total number of active subscriptions.
Sourcepub fn clear_mailboxes(&mut self)
pub fn clear_mailboxes(&mut self)
Clears all mailboxes without removing subscriptions.
Trait Implementations§
Source§impl Debug for MessageBus
impl Debug for MessageBus
Auto Trait Implementations§
impl Freeze for MessageBus
impl RefUnwindSafe for MessageBus
impl Send for MessageBus
impl Sync for MessageBus
impl Unpin for MessageBus
impl UnsafeUnpin for MessageBus
impl UnwindSafe for MessageBus
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request