nautilus_common::msgbus

Struct MessageBus

Source
pub struct MessageBus {
    pub trader_id: TraderId,
    pub instance_id: UUID4,
    pub name: String,
    pub has_backing: bool,
    pub switchboard: MessagingSwitchboard,
    /* 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.

§switchboard: MessagingSwitchboard

The switchboard for built-in endpoints.

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 memory_address(&self) -> String

Returns the message bus instances memory address.

Source

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

Returns the registered endpoint addresses.

Source

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

Returns the topics for active subscriptions.

Source

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

Returns whether there are subscribers for the given pattern.

Source

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

Returns the count of subscribers for the given pattern.

Source

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

Returns whether there are subscribers for the given pattern.

Source

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

Returns whether there are subscribers for the given pattern.

Source

pub fn is_registered<T: AsRef<str>>(&self, endpoint: T) -> bool

Returns whether there is a registered endpoint for the given pattern.

Source

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

Returns whether there are subscribers for the given pattern.

Source

pub const fn close(&self) -> Result<()>

Close the message bus which will close the sender channel and join the thread.

Source

pub fn register<T: AsRef<str>>( &mut self, endpoint: T, handler: ShareableMessageHandler, )

Registers the given handler for the endpoint address.

Source

pub fn deregister(&mut self, endpoint: &Ustr)

Deregisters the given handler for the endpoint address.

Source

pub fn subscribe<T: AsRef<str>>( &mut self, topic: T, handler: ShareableMessageHandler, priority: Option<u8>, )

Subscribes the given handler to the topic.

Source

pub fn unsubscribe<T: AsRef<str>>( &mut self, topic: T, handler: ShareableMessageHandler, )

Unsubscribes the given handler from the topic.

Source

pub fn get_endpoint<T: AsRef<str>>( &self, endpoint: T, ) -> Option<&ShareableMessageHandler>

Returns the handler for the given endpoint.

Source

pub fn matching_subscriptions<'a>( &'a self, pattern: &'a Ustr, ) -> Vec<&'a Subscription>

Source

pub fn send(&self, endpoint: &Ustr, message: &dyn Any)

Sends a message to an endpoint.

Source

pub fn publish(&self, topic: &Ustr, message: &dyn Any)

Publish a message to a topic.

Source§

impl MessageBus

Data specific functions.

Source

pub fn send_response(&self, message: DataResponse)

Send a DataResponse to an endpoint that must be an actor.

Source

pub fn publish_data(&self, topic: &Ustr, message: Data)

Publish [Data] to a topic.

Source§

impl MessageBus

Source

pub fn send_py(&self, endpoint: &str, message: PyObject)

Sends a message to a an endpoint.

Source

pub fn publish_py(&self, topic: &str, message: PyObject)

Publish a message to a topic.

Source

pub fn register_py(&mut self, endpoint: &str, handler: PythonMessageHandler)

Registers the given handler for the endpoint address.

Source

pub fn subscribe_py( slf: PyRefMut<'_, Self>, topic: &str, handler: PythonMessageHandler, priority: Option<u8>, )

Subscribes the given handler to the topic.

The priority for the subscription determines the ordering of handlers receiving messages being processed, higher priority handlers will receive messages before lower priority handlers.

Safety: Priority should be between 0 and 255

§Warnings

Assigning priority handling is an advanced feature which shouldn’t normally be needed by most users. Only assign a higher priority to the subscription if you are certain of what you’re doing. If an inappropriate priority is assigned then the handler may receive messages before core system components have been able to process necessary calculations and produce potential side effects for logically sound behavior.

Source

pub fn is_subscribed_py( &self, topic: &str, handler: PythonMessageHandler, ) -> bool

Returns whether there are subscribers for the given pattern.

Source

pub fn unsubscribe_py(&mut self, topic: &str, handler: PythonMessageHandler)

Unsubscribes the given handler from the topic.

Source

pub fn is_registered_py(&self, endpoint: &str) -> bool

Returns whether there are subscribers for the given pattern.

Source

pub fn deregister_py(&mut self, endpoint: &str)

Deregisters the given handler for the endpoint address.

Trait Implementations§

Source§

impl Default for MessageBus

Source§

fn default() -> Self

Creates a new default MessageBus instance.

Source§

impl IntoPy<Py<PyAny>> for MessageBus

Source§

fn into_py(self, py: Python<'_>) -> PyObject

Performs the conversion.
Source§

impl PyClass for MessageBus

Source§

type Frozen = False

Whether the pyclass is frozen. Read more
Source§

impl PyClassImpl for MessageBus

Source§

const IS_BASETYPE: bool = false

#[pyclass(subclass)]
Source§

const IS_SUBCLASS: bool = false

#[pyclass(extends=…)]
Source§

const IS_MAPPING: bool = false

#[pyclass(mapping)]
Source§

const IS_SEQUENCE: bool = false

#[pyclass(sequence)]
Source§

type BaseType = PyAny

Base class
Source§

type ThreadChecker = SendablePyClass<MessageBus>

This handles following two situations: Read more
Source§

type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild

Immutable or mutable
Source§

type Dict = PyClassDummySlot

Specify this class has #[pyclass(dict)] or not.
Source§

type WeakRef = PyClassDummySlot

Specify this class has #[pyclass(weakref)] or not.
Source§

type BaseNativeType = PyAny

The closest native ancestor. This is PyAny by default, and when you declare #[pyclass(extends=PyDict)], it’s PyDict.
Source§

fn items_iter() -> PyClassItemsIter

Source§

fn doc(py: Python<'_>) -> PyResult<&'static CStr>

Rendered class doc
Source§

fn lazy_type_object() -> &'static LazyTypeObject<Self>

§

fn dict_offset() -> Option<isize>

§

fn weaklist_offset() -> Option<isize>

Source§

impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a MessageBus

Source§

type Holder = Option<PyRef<'py, MessageBus>>

Source§

fn extract( obj: &'a Bound<'py, PyAny>, holder: &'a mut Self::Holder, ) -> PyResult<Self>

Source§

impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut MessageBus

Source§

type Holder = Option<PyRefMut<'py, MessageBus>>

Source§

fn extract( obj: &'a Bound<'py, PyAny>, holder: &'a mut Self::Holder, ) -> PyResult<Self>

Source§

impl PyMethods<MessageBus> for PyClassImplCollector<MessageBus>

Source§

fn py_methods(self) -> &'static PyClassItems

Source§

impl PyTypeInfo for MessageBus

Source§

const NAME: &'static str = "MessageBus"

Class name.
Source§

const MODULE: Option<&'static str> = _

Module name, if any.
Source§

fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject

Returns the PyTypeObject instance for this type.
§

fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>

Returns the safe abstraction over the type object.
§

fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type or a subclass of this type.
§

fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type.
Source§

impl DerefToPyAny for MessageBus

Source§

impl Send for MessageBus

Source§

impl Sync for MessageBus

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
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PyErrArguments for T
where T: IntoPy<Py<PyAny>> + Send + Sync,

§

fn arguments(self, py: Python<'_>) -> Py<PyAny>

Arguments for exception
§

impl<T> PyTypeCheck for T
where T: PyTypeInfo,

§

const NAME: &'static str = <T as PyTypeInfo>::NAME

Name of self. This is used in error messages, for example.
§

fn type_check(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of Self, which may include a subtype. Read more
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
§

impl<T> Ungil for T
where T: Send,