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
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 memory_address(&self) -> String
pub fn memory_address(&self) -> String
Returns the message bus instances memory address.
Sourcepub fn has_subscribers<T: AsRef<str>>(&self, pattern: T) -> bool
pub fn has_subscribers<T: AsRef<str>>(&self, pattern: T) -> bool
Returns whether there are subscribers for the given pattern
.
Sourcepub fn subscriptions_count<T: AsRef<str>>(&self, pattern: T) -> usize
pub fn subscriptions_count<T: AsRef<str>>(&self, pattern: T) -> usize
Returns the count of subscribers for the given pattern
.
Sourcepub fn subscriptions(&self) -> Vec<&Subscription>
pub fn subscriptions(&self) -> Vec<&Subscription>
Returns whether there are subscribers for the given pattern
.
Sourcepub fn subscription_handler_ids(&self) -> Vec<&str>
pub fn subscription_handler_ids(&self) -> Vec<&str>
Returns whether there are subscribers for the given pattern
.
Sourcepub fn is_registered<T: AsRef<str>>(&self, endpoint: T) -> bool
pub fn is_registered<T: AsRef<str>>(&self, endpoint: T) -> bool
Returns whether there is a registered endpoint for the given pattern
.
Sourcepub fn is_subscribed<T: AsRef<str>>(
&self,
topic: T,
handler: ShareableMessageHandler,
) -> bool
pub fn is_subscribed<T: AsRef<str>>( &self, topic: T, handler: ShareableMessageHandler, ) -> bool
Returns whether there are subscribers for the given 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.
Sourcepub fn register<T: AsRef<str>>(
&mut self,
endpoint: T,
handler: ShareableMessageHandler,
)
pub fn register<T: AsRef<str>>( &mut self, endpoint: T, handler: ShareableMessageHandler, )
Registers the given handler
for the endpoint
address.
Sourcepub fn deregister(&mut self, endpoint: &Ustr)
pub fn deregister(&mut self, endpoint: &Ustr)
Deregisters the given handler
for the endpoint
address.
Sourcepub fn subscribe<T: AsRef<str>>(
&mut self,
topic: T,
handler: ShareableMessageHandler,
priority: Option<u8>,
)
pub fn subscribe<T: AsRef<str>>( &mut self, topic: T, handler: ShareableMessageHandler, priority: Option<u8>, )
Subscribes the given handler
to the topic
.
Sourcepub fn unsubscribe<T: AsRef<str>>(
&mut self,
topic: T,
handler: ShareableMessageHandler,
)
pub fn unsubscribe<T: AsRef<str>>( &mut self, topic: T, handler: ShareableMessageHandler, )
Unsubscribes the given handler
from the topic
.
Sourcepub fn get_endpoint<T: AsRef<str>>(
&self,
endpoint: T,
) -> Option<&ShareableMessageHandler>
pub fn get_endpoint<T: AsRef<str>>( &self, endpoint: T, ) -> Option<&ShareableMessageHandler>
Returns the handler for the given endpoint
.
pub fn matching_subscriptions<'a>( &'a self, pattern: &'a Ustr, ) -> Vec<&'a Subscription>
Source§impl MessageBus
impl MessageBus
Data specific functions.
Sourcepub fn send_response(&self, message: DataResponse)
pub fn send_response(&self, message: DataResponse)
Send a DataResponse
to an endpoint that must be an actor.
Sourcepub fn publish_data(&self, topic: &Ustr, message: Data)
pub fn publish_data(&self, topic: &Ustr, message: Data)
Publish [Data
] to a topic.
Source§impl MessageBus
impl MessageBus
Sourcepub fn publish_py(&self, topic: &str, message: PyObject)
pub fn publish_py(&self, topic: &str, message: PyObject)
Publish a message to a topic.
Sourcepub fn register_py(&mut self, endpoint: &str, handler: PythonMessageHandler)
pub fn register_py(&mut self, endpoint: &str, handler: PythonMessageHandler)
Registers the given handler
for the endpoint
address.
Sourcepub fn subscribe_py(
slf: PyRefMut<'_, Self>,
topic: &str,
handler: PythonMessageHandler,
priority: Option<u8>,
)
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.
Sourcepub fn is_subscribed_py(
&self,
topic: &str,
handler: PythonMessageHandler,
) -> bool
pub fn is_subscribed_py( &self, topic: &str, handler: PythonMessageHandler, ) -> bool
Returns whether there are subscribers for the given pattern
.
Sourcepub fn unsubscribe_py(&mut self, topic: &str, handler: PythonMessageHandler)
pub fn unsubscribe_py(&mut self, topic: &str, handler: PythonMessageHandler)
Unsubscribes the given handler
from the topic
.
Sourcepub fn is_registered_py(&self, endpoint: &str) -> bool
pub fn is_registered_py(&self, endpoint: &str) -> bool
Returns whether there are subscribers for the given pattern
.
Sourcepub fn deregister_py(&mut self, endpoint: &str)
pub fn deregister_py(&mut self, endpoint: &str)
Deregisters the given handler
for the endpoint
address.
Trait Implementations§
Source§impl Default for MessageBus
impl Default for MessageBus
Source§fn default() -> Self
fn default() -> Self
Creates a new default MessageBus
instance.
Source§impl IntoPy<Py<PyAny>> for MessageBus
impl IntoPy<Py<PyAny>> for MessageBus
Source§impl PyClass for MessageBus
impl PyClass for MessageBus
Source§impl PyClassImpl for MessageBus
impl PyClassImpl for MessageBus
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§type ThreadChecker = SendablePyClass<MessageBus>
type ThreadChecker = SendablePyClass<MessageBus>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny
by default, and when you declare
#[pyclass(extends=PyDict)]
, it’s PyDict
.fn items_iter() -> PyClassItemsIter
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
impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a MessageBus
Source§impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut MessageBus
impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut MessageBus
Source§impl PyMethods<MessageBus> for PyClassImplCollector<MessageBus>
impl PyMethods<MessageBus> for PyClassImplCollector<MessageBus>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for MessageBus
impl PyTypeInfo for MessageBus
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
§fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
§fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool
fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool
object
is an instance of this type or a subclass of this type.§fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
object
is an instance of this type.impl DerefToPyAny for MessageBus
impl Send for MessageBus
impl Sync for MessageBus
Auto Trait Implementations§
impl Freeze for MessageBus
impl !RefUnwindSafe for MessageBus
impl Unpin 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