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(&self, pattern: &str) -> bool

Returns whether there are 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(&self, endpoint: &str) -> bool

Returns whether there are subscribers for the given pattern.

source

pub fn is_subscribed( &self, topic: &str, 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(&mut self, endpoint: Ustr, 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( &mut self, topic: Ustr, handler: ShareableMessageHandler, priority: Option<u8>, )

Subscribes the given handler to the topic.

source

pub fn unsubscribe(&mut self, topic: Ustr, handler: ShareableMessageHandler)

Unsubscribes the given handler from the topic.

source

pub fn get_endpoint(&self, endpoint: &Ustr) -> 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: &str, 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

Returns the “default value” for a type. Read more
source§

impl HasPyGilRef for MessageBus

source§

type AsRefTarget = PyCell<MessageBus>

Utility type to make Py::as_ref work.
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(py: Python<'_>) -> &PyType

👎Deprecated since 0.21.0: PyTypeInfo::type_object will be replaced by PyTypeInfo::type_object_bound in a future PyO3 version
Returns the safe abstraction over the type object.
§

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

Returns the safe abstraction over the type object.
§

fn is_type_of(object: &PyAny) -> bool

👎Deprecated since 0.21.0: PyTypeInfo::is_type_of will be replaced by PyTypeInfo::is_type_of_bound in a future PyO3 version
Checks if object is an instance of this type or a subclass of this type.
§

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(object: &PyAny) -> bool

👎Deprecated since 0.21.0: PyTypeInfo::is_exact_type_of will be replaced by PyTypeInfo::is_exact_type_of_bound in a future PyO3 version
Checks if object is an instance 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,