pub struct MessageBus { /* private fields */ }Expand description
Async message bus that decouples chat channels from the agent core
Channels push messages to the inbound queue, and the agent processes them and pushes responses to the outbound queue.
Implementations§
Source§impl MessageBus
impl MessageBus
Sourcepub fn publish_event(
&self,
channel: impl Into<String>,
chat_id: impl Into<String>,
event: AgentEvent,
) -> Result<()>
pub fn publish_event( &self, channel: impl Into<String>, chat_id: impl Into<String>, event: AgentEvent, ) -> Result<()>
Publish an event to the broadcast channel
Sourcepub fn subscribe_events(&self) -> Receiver<AgentBusEvent>
pub fn subscribe_events(&self) -> Receiver<AgentBusEvent>
Subscribe to the event broadcast channel
Sourcepub async fn take_inbound_receiver(
&self,
) -> Option<UnboundedReceiver<InboundMessage>>
pub async fn take_inbound_receiver( &self, ) -> Option<UnboundedReceiver<InboundMessage>>
Take the inbound receiver (can only be called once)
Sourcepub async fn take_outbound_receiver(
&self,
) -> Option<UnboundedReceiver<OutboundMessage>>
pub async fn take_outbound_receiver( &self, ) -> Option<UnboundedReceiver<OutboundMessage>>
Take the outbound receiver (can only be called once)
Sourcepub fn publish_inbound(&self, msg: InboundMessage) -> Result<()>
pub fn publish_inbound(&self, msg: InboundMessage) -> Result<()>
Publish a message from a channel to the agent
Sourcepub fn publish_outbound(&self, msg: OutboundMessage) -> Result<()>
pub fn publish_outbound(&self, msg: OutboundMessage) -> Result<()>
Publish a response from the agent to channels
Sourcepub async fn subscribe_outbound<F, Fut>(
&self,
channel: impl Into<String>,
callback: F,
)
pub async fn subscribe_outbound<F, Fut>( &self, channel: impl Into<String>, callback: F, )
Subscribe to outbound messages for a specific channel with a callback
Sourcepub async fn dispatch_outbound_loop(&self)
pub async fn dispatch_outbound_loop(&self)
Dispatch outbound messages to subscribed channels Run this as a background task
Sourcepub async fn is_running(&self) -> bool
pub async fn is_running(&self) -> bool
Check if the bus is running
Trait Implementations§
Source§impl Clone for MessageBus
impl Clone for MessageBus
Source§fn clone(&self) -> MessageBus
fn clone(&self) -> MessageBus
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto 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
Mutably borrows from an owned value. Read more