Crate gc_message_broker
Expand description
The gc_message_broker crate provides message brokers that allow plugins to communicate with each other.
The crate provides two types of brokers:
- A concurrent message dispatcher that uses a crossbeam_channel channel to send messages to subscribers.
- A sequential message dispatcher that uses the publisher control flow to send messages to subscribers.
The broker supports subscribing to a single datapoint or to register a broadcast subscriber that will receive all messages. In order to register a broadcast subscriber, the user must register before the broker is built using the register_concurrent_broadcast or register_sequential_broadcast methods. To register a subscriber for a single datapoint, it is recommend to use the add_concurrent_subscriber or add_sequential_subscriber methods after the broker is built. A publisher can be spawned by invoking the GCMessageBroker::generate_publisher method.
The concurrent (async) broker will only be started if run is called.
The message broker is also responsible for applying scaling transformations and allocating the datapoint value before sending it to the subscribers.
ยงRecommendations:
- Using a concurrent message dispatcher broker is recommended for subscriber plugins that do not have harsh requirements for end2end message passing delays.
- Using a sequential message dispatcher broker is recommended for subscriber plugins that require very low delay on message dispatch, it also should be considered that the publisher will be blocked while the subscriber is processing the message.
ยงImplementation details:
The broker distribute messages based on the datapoint ID, which is stored in a array, providing a time complexity of O(1) to find the subscribers for a given DatapointValue.
Modulesยง
- concurrent_
publisher ๐ - datapoint_
mapping ๐ - message_
broker ๐ - message_
broker_ ๐builder - message_
dispatcher ๐ - message_
publisher ๐
Structsยง
- GCMessage
Broker - Message broker used to distribute messages to the subscribers. This module should be built using the GCMessageBrokerBuilder that will take care of all the necessary configurations. Whenever the broker is built, it can be used to generate multiple publishers, the broker for sequential messages will start routing the messages to the sequential subscribers immediately. Although, the concurrent subscribers messages will only be processed once the run is called.
- GCMessage
Broker Builder - Builder for the GCMessageBroker. This builder allows the user to configure the broker with the desired options. Every subscriber should be registered before building the broker, this ensures the list of subscribers is immutable providing higher performance and reducing asynchronous complexity.
- GCMessage
Publisher - Message publisher used to publish messages to the broker.
- Scale
Transformation
Type Aliasesยง
- Shared
Datapoint ๐Mapping - Shared
Receiver ๐Channel - Shared
Sender ๐Channel