pub struct MessageBus {
agents: Mutex<HashMap<String, AgentConnection>>,
offline_queues: Mutex<HashMap<String, VecDeque<BusMessage>>>,
}Fields§
§agents: Mutex<HashMap<String, AgentConnection>>§offline_queues: Mutex<HashMap<String, VecDeque<BusMessage>>>Implementations§
Source§impl MessageBus
impl MessageBus
pub fn new() -> Self
Sourcepub fn register(
&self,
agent_id: &str,
connection_type: &str,
) -> UnboundedReceiver<BusMessage>
pub fn register( &self, agent_id: &str, connection_type: &str, ) -> UnboundedReceiver<BusMessage>
Register an agent on the bus with a WebSocket push channel. Returns a receiver for messages pushed to this agent.
Sourcepub fn register_http(&self, agent_id: &str)
pub fn register_http(&self, agent_id: &str)
Register an HTTP-polling agent (no WebSocket push channel).
Messages sent to this agent are queued in the offline queue and
retrieved via read_messages.
Sourcepub fn unregister(&self, agent_id: &str)
pub fn unregister(&self, agent_id: &str)
Unregister an agent from the bus.
Sourcepub fn touch(&self, agent_id: &str)
pub fn touch(&self, agent_id: &str)
Update last_seen timestamp for an agent (called on HTTP polling).
Sourcepub fn inject(
&self,
from: &str,
target: &str,
message: &str,
priority: Priority,
) -> Result<String, String>
pub fn inject( &self, from: &str, target: &str, message: &str, priority: Priority, ) -> Result<String, String>
Inject a message into an agent’s terminal (jekt). This is the same as send but with MessageType::Inject.
Sourcepub fn broadcast(
&self,
from: &str,
payload: &str,
priority: Priority,
) -> Result<usize, String>
pub fn broadcast( &self, from: &str, payload: &str, priority: Priority, ) -> Result<usize, String>
Broadcast a message to all connected agents (except sender).
Sourcepub fn list_agents(&self) -> Vec<AgentInfo>
pub fn list_agents(&self) -> Vec<AgentInfo>
List all registered agents.
Sourcepub fn read_messages(&self, agent_id: &str, limit: usize) -> Vec<BusMessage>
pub fn read_messages(&self, agent_id: &str, limit: usize) -> Vec<BusMessage>
Read (and drain) queued offline messages for an agent. Used by HTTP-polling agents that don’t have a WebSocket connection.
Sourcepub fn delete_messages(&self, agent_id: &str, message_ids: &[String]) -> usize
pub fn delete_messages(&self, agent_id: &str, message_ids: &[String]) -> usize
Delete specific messages by ID from an agent’s offline queue.
fn queue_offline(&self, msg: BusMessage)
fn drain_offline_queue(&self, agent_id: &str)
Auto Trait Implementations§
impl !Freeze for MessageBus
impl !RefUnwindSafe for MessageBus
impl Send for MessageBus
impl Sync for MessageBus
impl Unpin 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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.