Skip to main content

MessageBus

Struct MessageBus 

Source
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: TraderId

The trader ID associated with the message bus.

§instance_id: UUID4

The instance ID associated with the message bus.

§name: String

The name for the message bus.

§has_backing: bool

If the message bus is backed by a database.

Implementations§

Source§

impl MessageBus

Source

pub fn new( trader_id: TraderId, instance_id: UUID4, name: Option<String>, _config: Option<HashMap<String, Value>>, ) -> Self

Creates a new MessageBus instance.

Source

pub fn register_message_bus(self) -> Rc<RefCell<Self>>

Registers message bus for the current thread.

Source

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).

Source

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).

Source

pub fn mem_address(&self) -> String

Returns the memory address of this instance as a hexadecimal string.

Source

pub fn switchboard(&self) -> &MessagingSwitchboard

Returns a reference to the switchboard.

Source

pub fn endpoints(&self) -> Vec<&str>

Returns the registered endpoint addresses.

Source

pub fn patterns(&self) -> Vec<&str>

Returns actively subscribed patterns.

Source

pub fn has_subscribers<T: AsRef<str>>(&self, topic: T) -> bool

Returns whether there are subscribers for the topic.

Source

pub fn subscriptions_count<T: AsRef<str>>(&self, topic: T) -> usize

Returns the count of subscribers for the topic.

§Panics

Returns an error if the topic is not valid.

Source

pub fn subscriptions(&self) -> Vec<&Subscription>

Returns active subscriptions.

Source

pub fn subscription_handler_ids(&self) -> Vec<&str>

Returns the handler IDs for actively subscribed patterns.

Source

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.

Source

pub fn is_subscribed<T: AsRef<str>>( &self, pattern: T, handler: ShareableMessageHandler, ) -> bool

Returns whether the handler is subscribed to the pattern.

Source

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).

Source

pub fn get_endpoint( &self, endpoint: MStr<Endpoint>, ) -> Option<&ShareableMessageHandler>

Returns the handler for the endpoint.

Source

pub fn get_response_handler( &self, correlation_id: &UUID4, ) -> Option<&ShareableMessageHandler>

Returns the handler for the correlation_id.

Source

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.

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MessageBus

Source§

fn default() -> Self

Creates a new default MessageBus instance.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more