pub struct AgentMessageBus { /* private fields */ }Expand description
Agent Message Bus for inter-agent communication
Implementations§
Source§impl AgentMessageBus
impl AgentMessageBus
Sourcepub fn with_config(max_history_size: usize, max_queue_size: usize) -> Self
pub fn with_config(max_history_size: usize, max_queue_size: usize) -> Self
Create a new message bus with custom settings
Sourcepub fn subscribe(&mut self, agent_id: impl Into<String>, types: Vec<String>)
pub fn subscribe(&mut self, agent_id: impl Into<String>, types: Vec<String>)
Subscribe an agent to receive messages
Sourcepub fn unsubscribe(&mut self, agent_id: &str)
pub fn unsubscribe(&mut self, agent_id: &str)
Unsubscribe an agent
Sourcepub fn is_subscribed(&self, agent_id: &str) -> bool
pub fn is_subscribed(&self, agent_id: &str) -> bool
Check if an agent is subscribed
Sourcepub fn get_subscription(&self, agent_id: &str) -> Option<&MessageSubscription>
pub fn get_subscription(&self, agent_id: &str) -> Option<&MessageSubscription>
Get subscription for an agent
Sourcepub fn send(&mut self, message: AgentMessage) -> MessageBusResult<()>
pub fn send(&mut self, message: AgentMessage) -> MessageBusResult<()>
Send a message to a specific agent or broadcast
Sourcepub fn broadcast(
&mut self,
message_type: &str,
payload: Value,
sender: &str,
) -> MessageBusResult<()>
pub fn broadcast( &mut self, message_type: &str, payload: Value, sender: &str, ) -> MessageBusResult<()>
Broadcast a message to all subscribed agents
Sourcepub fn get_queue(&self, agent_id: &str) -> Vec<AgentMessage>
pub fn get_queue(&self, agent_id: &str) -> Vec<AgentMessage>
Get all messages in an agent’s queue (without removing)
Sourcepub fn dequeue(&mut self, agent_id: &str, count: usize) -> Vec<AgentMessage>
pub fn dequeue(&mut self, agent_id: &str, count: usize) -> Vec<AgentMessage>
Dequeue messages from an agent’s queue (removes them)
Sourcepub fn dequeue_all(&mut self, agent_id: &str) -> Vec<AgentMessage>
pub fn dequeue_all(&mut self, agent_id: &str) -> Vec<AgentMessage>
Dequeue all messages from an agent’s queue
Sourcepub fn queue_size(&self, agent_id: &str) -> usize
pub fn queue_size(&self, agent_id: &str) -> usize
Get the number of messages in an agent’s queue
Sourcepub fn has_messages(&self, agent_id: &str) -> bool
pub fn has_messages(&self, agent_id: &str) -> bool
Check if an agent has pending messages
Sourcepub fn get_history(&self, limit: Option<usize>) -> Vec<AgentMessage>
pub fn get_history(&self, limit: Option<usize>) -> Vec<AgentMessage>
Get message history
Sourcepub fn clear_history(&mut self)
pub fn clear_history(&mut self)
Clear message history
Sourcepub fn get_subscribed_agents(&self) -> Vec<String>
pub fn get_subscribed_agents(&self) -> Vec<String>
Get all subscribed agent IDs
Sourcepub fn cleanup_expired(&mut self) -> usize
pub fn cleanup_expired(&mut self) -> usize
Remove expired messages from all queues
Sourcepub fn stats(&self) -> MessageBusStats
pub fn stats(&self) -> MessageBusStats
Get statistics about the message bus
Sourcepub fn prepare_request(
&mut self,
to: &str,
message_type: &str,
payload: Value,
from: &str,
timeout: Duration,
) -> MessageBusResult<(String, Receiver<Value>)>
pub fn prepare_request( &mut self, to: &str, message_type: &str, payload: Value, from: &str, timeout: Duration, ) -> MessageBusResult<(String, Receiver<Value>)>
Send a request message and wait for a response with timeout
This method sends a message to the target agent with requires_response set to true,
and waits for a response within the specified timeout duration.
§Arguments
to- Target agent IDmessage_type- Type of the messagepayload- Message payloadfrom- Sender agent IDtimeout- Maximum time to wait for a response
§Returns
Ok(Value)- The response payloadErr(MessageBusError::RequestTimeout)- If no response is received within timeoutErr(MessageBusError::MessageExpired)- If the message expires before delivery
Sourcepub fn respond(
&mut self,
request: &AgentMessage,
payload: Value,
) -> MessageBusResult<()>
pub fn respond( &mut self, request: &AgentMessage, payload: Value, ) -> MessageBusResult<()>
Send a response to a request message
This method sends a response to a previously received request message. The response is delivered to the original requester.
§Arguments
request- The original request messagepayload- Response payload
§Returns
Ok(())- If the response was sent successfullyErr(MessageBusError::InvalidMessage)- If the request doesn’t require a responseErr(MessageBusError::NoResponse)- If no pending request was found
Sourcepub fn is_request_pending(&self, request_id: &str) -> bool
pub fn is_request_pending(&self, request_id: &str) -> bool
Check if a request is still pending
Sourcepub fn pending_request_count(&self) -> usize
pub fn pending_request_count(&self) -> usize
Get the number of pending requests
Sourcepub fn cancel_request(&mut self, request_id: &str) -> bool
pub fn cancel_request(&mut self, request_id: &str) -> bool
Cancel a pending request
Removes the pending request without sending a response. Returns true if the request was found and cancelled.
Sourcepub fn cleanup_expired_requests(&mut self) -> usize
pub fn cleanup_expired_requests(&mut self) -> usize
Cleanup expired pending requests
Removes all pending requests that have exceeded their timeout. Returns the number of expired requests removed.
Sourcepub fn get_response(
&mut self,
agent_id: &str,
request_id: &str,
) -> Option<AgentMessage>
pub fn get_response( &mut self, agent_id: &str, request_id: &str, ) -> Option<AgentMessage>
Get a response message from an agent’s queue by request ID
Searches the agent’s queue for a response to the specified request. Returns and removes the response message if found.
Sourcepub fn find_message_in_history(&self, message_id: &str) -> Option<&AgentMessage>
pub fn find_message_in_history(&self, message_id: &str) -> Option<&AgentMessage>
Find a message in history by ID
Sourcepub fn get_responses_from_history(&self, request_id: &str) -> Vec<&AgentMessage>
pub fn get_responses_from_history(&self, request_id: &str) -> Vec<&AgentMessage>
Get all response messages for a specific request from history
Trait Implementations§
Source§impl Debug for AgentMessageBus
impl Debug for AgentMessageBus
Auto Trait Implementations§
impl Freeze for AgentMessageBus
impl !RefUnwindSafe for AgentMessageBus
impl Send for AgentMessageBus
impl Sync for AgentMessageBus
impl Unpin for AgentMessageBus
impl UnsafeUnpin for AgentMessageBus
impl !UnwindSafe for AgentMessageBus
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§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::RequestSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.