pub struct MessageBus {
pub trader_id: TraderId,
pub instance_id: UUID4,
pub name: String,
pub has_backing: bool,
/* private fields */
}Expand description
A generic message bus to facilitate various messaging patterns.
The bus provides both a producer and consumer API for Pub/Sub, Req/Rep, as well as direct point-to-point messaging to registered endpoints.
Pub/Sub wildcard patterns for hierarchical topics are possible:
*asterisk represents one or more characters in a pattern.?question mark represents a single character in a pattern.
Given a topic and pattern potentially containing wildcard characters, i.e.
* and ?, where ? can match any single character in the topic, and *
can match any number of characters including zero characters.
The asterisk in a wildcard matches any character zero or more times. For
example, comp* matches anything beginning with comp which means comp,
complete, and computer are all matched.
A question mark matches a single character once. For example, c?mp matches
camp and comp. The question mark can also be used more than once.
For example, c??p would match both of the above examples and coop.
Fields§
§trader_id: TraderIdThe trader ID associated with the message bus.
instance_id: UUID4The instance ID associated with the message bus.
name: StringThe name for the message bus.
has_backing: boolIf the message bus is backed by a database.
Implementations§
Source§impl MessageBus
impl MessageBus
Sourcepub fn new(
trader_id: TraderId,
instance_id: UUID4,
name: Option<String>,
_config: Option<HashMap<String, Value>>,
) -> Self
pub fn new( trader_id: TraderId, instance_id: UUID4, name: Option<String>, _config: Option<HashMap<String, Value>>, ) -> Self
Creates a new MessageBus instance.
Sourcepub fn register_message_bus(self) -> Rc<RefCell<Self>>
pub fn register_message_bus(self) -> Rc<RefCell<Self>>
Registers message bus for the current thread.
Sourcepub fn router<T: 'static>(&mut self) -> &mut TopicRouter<T>
pub fn router<T: 'static>(&mut self) -> &mut TopicRouter<T>
Gets or creates a typed router for custom message type T.
§Panics
Panics if the stored router type doesn’t match T (internal bug).
Sourcepub fn endpoint_map<T: 'static>(&mut self) -> &mut EndpointMap<T>
pub fn endpoint_map<T: 'static>(&mut self) -> &mut EndpointMap<T>
Gets or creates a typed endpoint map for custom message type T.
§Panics
Panics if the stored endpoint map type doesn’t match T (internal bug).
Sourcepub fn mem_address(&self) -> String
pub fn mem_address(&self) -> String
Returns the memory address of this instance as a hexadecimal string.
Sourcepub fn switchboard(&self) -> &MessagingSwitchboard
pub fn switchboard(&self) -> &MessagingSwitchboard
Returns a reference to the switchboard.
Sourcepub fn has_subscribers<T: AsRef<str>>(&self, topic: T) -> bool
pub fn has_subscribers<T: AsRef<str>>(&self, topic: T) -> bool
Returns whether there are subscribers for the topic.
Sourcepub fn subscriptions_count<T: AsRef<str>>(&self, topic: T) -> usize
pub fn subscriptions_count<T: AsRef<str>>(&self, topic: T) -> usize
Sourcepub fn subscriptions(&self) -> Vec<&Subscription>
pub fn subscriptions(&self) -> Vec<&Subscription>
Returns active subscriptions.
Sourcepub fn subscription_handler_ids(&self) -> Vec<&str>
pub fn subscription_handler_ids(&self) -> Vec<&str>
Returns the handler IDs for actively subscribed patterns.
Sourcepub fn is_registered<T: Into<MStr<Endpoint>>>(&self, endpoint: T) -> bool
pub fn is_registered<T: Into<MStr<Endpoint>>>(&self, endpoint: T) -> bool
Returns whether the endpoint is registered.
§Panics
Returns an error if the endpoint is not valid topic string.
Sourcepub fn is_subscribed<T: AsRef<str>>(
&self,
pattern: T,
handler: ShareableMessageHandler,
) -> bool
pub fn is_subscribed<T: AsRef<str>>( &self, pattern: T, handler: ShareableMessageHandler, ) -> bool
Returns whether the handler is subscribed to the pattern.
Sourcepub const fn close(&self) -> Result<()>
pub const fn close(&self) -> Result<()>
Close the message bus which will close the sender channel and join the thread.
§Errors
This function never returns an error (TBD once backing database added).
Sourcepub fn get_endpoint(
&self,
endpoint: MStr<Endpoint>,
) -> Option<&ShareableMessageHandler>
pub fn get_endpoint( &self, endpoint: MStr<Endpoint>, ) -> Option<&ShareableMessageHandler>
Returns the handler for the endpoint.
Sourcepub fn get_response_handler(
&self,
correlation_id: &UUID4,
) -> Option<&ShareableMessageHandler>
pub fn get_response_handler( &self, correlation_id: &UUID4, ) -> Option<&ShareableMessageHandler>
Returns the handler for the correlation_id.
Sourcepub fn matching_subscriptions<T: Into<MStr<Topic>>>(
&mut self,
topic: T,
) -> Vec<Subscription>
pub fn matching_subscriptions<T: Into<MStr<Topic>>>( &mut self, topic: T, ) -> Vec<Subscription>
Finds the subscriptions which match the topic and caches the
results in the patterns map.
Sourcepub fn register_response_handler(
&mut self,
correlation_id: &UUID4,
handler: ShareableMessageHandler,
) -> Result<()>
pub fn register_response_handler( &mut self, correlation_id: &UUID4, handler: ShareableMessageHandler, ) -> Result<()>
Registers a response handler for a specific correlation ID.
§Errors
Returns an error if handler is already registered for the correlation_id.
Trait Implementations§
Source§impl Debug for MessageBus
impl Debug for MessageBus
Source§impl Default for MessageBus
impl Default for MessageBus
Source§fn default() -> Self
fn default() -> Self
Creates a new default MessageBus instance.
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more