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 set_external_egress( &mut self, external_egress: Box<dyn MessageBusExternalEgress>, encoding: SerializationEncoding, )

Sets external egress for serialized published messages.

Source

pub fn set_external_egress_config( &mut self, external_egress: Box<dyn MessageBusExternalEgress>, config: &MessageBusConfig, ) -> ConfigResult<()>

Sets external egress and category encoding policy from a validated config.

§Errors

Returns a crate::config::ConfigError if the config selects an unsupported encoding.

Source

pub fn set_types_filter(&mut self, filter: Vec<String>)

Sets the type names excluded from external publishing.

Source

pub fn add_streaming_type(&mut self, payload_type: BusPayloadType)

Registers a payload type for external-to-internal streaming.

Source

pub fn is_streaming_type(&self, payload_type: BusPayloadType) -> bool

Returns whether the payload type is registered for external-to-internal streaming.

Source

pub fn clear_streaming_types(&mut self)

Clears all payload types registered for external-to-internal streaming.

Source

pub fn dispose(&mut self)

Disposes of the message bus, clearing all subscriptions, endpoints, and handler references.

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 const fn sent_count(&self) -> u64

Returns the total count of messages sent to endpoints.

Source

pub const fn req_count(&self) -> u64

Returns the total count of requests sent to endpoints.

Source

pub const fn res_count(&self) -> u64

Returns the total count of responses sent to registered handlers.

Source

pub const fn pub_count(&self) -> u64

Returns the total count of messages published to topics.

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) -> Result<bool>

Returns whether there are subscribers for the topic.

§Errors

Returns an error if the topic is not a valid topic string.

Source

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

Returns the count of subscribers for the topic.

§Errors

Returns an error if the topic is not a valid topic string.

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

Panics if the endpoint conversion to MStr<Endpoint> fails.

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 fn close(&mut 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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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