Expand description
In-memory message bus for intra-process communication.
§Messaging patterns
- Point-to-point: Send messages to named endpoints via
send_*functions. - Pub/sub: Publish messages to topics via
publish_*, subscribers receive all messages matching their pattern. - Request/response: Register correlation IDs for response sequence tracking.
§Architecture
The bus uses thread-local storage for single-threaded async runtimes. Each
thread gets its own MessageBus instance, avoiding synchronization overhead.
Two routing mechanisms serve different needs:
- Typed routing (
publish_quote,subscribe_quotes): Zero-cost dispatch for known types. Handlers receive&Tdirectly with no runtime type checking. - Any-based routing (
publish_any,subscribe_any): Flexible dispatch for custom types and Python interop. Handlers receive&dyn Any.
See core module documentation for design decisions and performance details.
Re-exports§
pub use self::core::MessageBus;pub use self::core::Subscription;pub use self::message::BusMessage;pub use self::mstr::Endpoint;pub use self::mstr::MStr;pub use self::mstr::Pattern;pub use self::mstr::Topic;pub use self::switchboard::MessagingSwitchboard;pub use self::typed_endpoints::EndpointMap;pub use self::typed_endpoints::IntoEndpointMap;pub use self::typed_handler::CallbackHandler;pub use self::typed_handler::Handler;pub use self::typed_handler::IntoHandler;pub use self::typed_handler::TypedHandler;pub use self::typed_handler::TypedIntoHandler;pub use self::typed_router::TopicRouter;pub use self::typed_router::TypedSubscription;
Modules§
- core
- Core message bus implementation.
- database
- matching
- Pattern matching for message bus topic subscriptions.
- message
- mstr
- Type-safe string wrappers for message bus patterns, topics, and endpoints.
- stubs
- switchboard
- typed_
endpoints - Type-safe endpoint mapping for point-to-point messaging.
- typed_
handler - Compile-time type-safe message handler infrastructure.
- typed_
router - Type-safe topic routing for pub/sub messaging.
Functions§
- deregister_
any - Deregisters the handler for an endpoint (Any-based).
- exact_
subscriber_ count_ bars - Returns the exact subscriber count for bars on a topic, excluding wildcard pattern subscriptions.
- get_
message_ bus - Gets the thread-local message bus.
- is_
subscribed_ any - Checks if a handler is subscribed to a pattern (Any-based).
- publish_
account_ state - Publishes an account state to subscribers on a topic.
- publish_
any - Publishes a message to the topic using runtime type dispatch (Any).
- publish_
bar - Publishes a bar to subscribers on a topic.
- publish_
book - Publishes an order book snapshot to subscribers on a topic.
- publish_
defi_ block - Publishes a DeFi block to subscribers on a topic.
- publish_
defi_ collect - Publishes a DeFi fee collect to subscribers on a topic.
- publish_
defi_ flash - Publishes a DeFi flash loan to subscribers on a topic.
- publish_
defi_ liquidity - Publishes a DeFi liquidity update to subscribers on a topic.
- publish_
defi_ pool - Publishes a DeFi pool to subscribers on a topic.
- publish_
defi_ swap - Publishes a DeFi pool swap to subscribers on a topic.
- publish_
deltas - Publishes order book deltas to subscribers on a topic.
- publish_
depth10 - Publishes order book depth10 to subscribers on a topic.
- publish_
funding_ rate - Publishes a funding rate update to subscribers on a topic.
- publish_
greeks - Publishes greeks data to subscribers on a topic.
- publish_
index_ price - Publishes an index price update to subscribers on a topic.
- publish_
mark_ price - Publishes a mark price update to subscribers on a topic.
- publish_
order_ event - Publishes an order event to subscribers on a topic.
- publish_
position_ event - Publishes a position event to subscribers on a topic.
- publish_
quote - Publishes a quote tick to subscribers on a topic.
- publish_
trade - Publishes a trade tick to subscribers on a topic.
- register_
account_ state_ endpoint - Registers an account state handler at an endpoint.
- register_
any - Registers a handler for an endpoint using runtime type dispatch (Any).
- register_
bar_ endpoint - Registers a bar handler at an endpoint.
- register_
data_ command_ endpoint - Registers a data command handler at an endpoint (ownership-based).
- register_
data_ endpoint - Registers a data handler at an endpoint (ownership-based).
- register_
data_ response_ endpoint - Registers a data response handler at an endpoint (ownership-based).
- register_
defi_ data_ endpoint - Registers a DeFi data handler at an endpoint (ownership-based).
- register_
execution_ report_ endpoint - Registers an execution report handler at an endpoint (ownership-based).
- register_
order_ event_ endpoint - Registers an order event handler at an endpoint (ownership-based).
- register_
quote_ endpoint - Registers a quote tick handler at an endpoint.
- register_
response_ handler - Registers a response handler for a correlation ID.
- register_
trade_ endpoint - Registers a trade tick handler at an endpoint.
- register_
trading_ command_ endpoint - Registers a trading command handler at an endpoint (ownership-based).
- remove_
order_ event_ handler - Removes a specific order event handler by pattern and handler ID.
- remove_
position_ event_ handler - Removes a specific position event handler by pattern and handler ID.
- send_
account_ state - Sends an account state to an endpoint handler.
- send_
any - Sends a message to an endpoint handler using runtime type dispatch (Any).
- send_
any_ value - Sends a message to an endpoint, converting to Any (convenience wrapper).
- send_
bar - Sends a bar to an endpoint handler.
- send_
data - Sends data to an endpoint handler, transferring ownership.
- send_
data_ command - Sends a data command to an endpoint handler, transferring ownership.
- send_
data_ response - Sends a data response to an endpoint handler, transferring ownership.
- send_
defi_ data - Sends DeFi data to an endpoint handler, transferring ownership.
- send_
execution_ report - Sends an execution report to an endpoint handler, transferring ownership.
- send_
order_ event - Sends an order event to an endpoint handler, transferring ownership.
- send_
quote - Sends a quote tick to an endpoint handler.
- send_
response - Sends the
DataResponseto the registered correlation ID handler. - send_
trade - Sends a trade tick to an endpoint handler.
- send_
trading_ command - Sends a trading command to an endpoint handler, transferring ownership.
- set_
message_ bus - Sets the thread-local message bus.
- subscribe_
account_ state - Subscribes a handler to account state updates matching a pattern.
- subscribe_
any - Subscribes a handler to a pattern using runtime type dispatch (Any).
- subscribe_
bars - Subscribes a handler to bars matching a pattern.
- subscribe_
book_ deltas - Subscribes a handler to order book deltas matching a pattern.
- subscribe_
book_ depth10 - Subscribes a handler to order book depth10 snapshots matching a pattern.
- subscribe_
book_ snapshots - Subscribes a handler to order book snapshots matching a pattern.
- subscribe_
defi_ blocks - Subscribes a handler to DeFi blocks matching a pattern.
- subscribe_
defi_ collects - Subscribes a handler to DeFi fee collects matching a pattern.
- subscribe_
defi_ flash - Subscribes a handler to DeFi flash loans matching a pattern.
- subscribe_
defi_ liquidity - Subscribes a handler to DeFi liquidity updates matching a pattern.
- subscribe_
defi_ pools - Subscribes a handler to DeFi pools matching a pattern.
- subscribe_
defi_ swaps - Subscribes a handler to DeFi pool swaps matching a pattern.
- subscribe_
funding_ rates - Subscribes a handler to funding rate updates matching a pattern.
- subscribe_
greeks - Subscribes a handler to greeks data matching a pattern.
- subscribe_
index_ prices - Subscribes a handler to index price updates matching a pattern.
- subscribe_
instrument_ close - Subscribes a handler to instrument close messages matching a pattern.
- subscribe_
instruments - Subscribes a handler to instrument messages matching a pattern.
- subscribe_
mark_ prices - Subscribes a handler to mark price updates matching a pattern.
- subscribe_
order_ events - Subscribes a handler to order events matching a pattern.
- subscribe_
position_ events - Subscribes a handler to position events matching a pattern.
- subscribe_
positions - Subscribes a handler to positions matching a pattern.
- subscribe_
quotes - Subscribes a handler to quote ticks matching a pattern.
- subscribe_
trades - Subscribes a handler to trade ticks matching a pattern.
- subscriber_
count_ book_ snapshots - Returns the subscriber count for order book snapshots on a topic.
- subscriber_
count_ deltas - Returns the subscriber count for order book deltas on a topic.
- subscriber_
count_ depth10 - Returns the subscriber count for order book depth10 on a topic.
- subscriptions_
count_ any - Returns the count of Any-based subscriptions for a topic.
- unsubscribe_
account_ state - Unsubscribes a handler from account state updates.
- unsubscribe_
any - Unsubscribes a handler from a pattern (Any-based).
- unsubscribe_
bars - Unsubscribes a handler from bars.
- unsubscribe_
book_ deltas - Unsubscribes a handler from order book deltas.
- unsubscribe_
book_ depth10 - Unsubscribes a handler from order book depth10 snapshots.
- unsubscribe_
book_ snapshots - Unsubscribes a handler from order book snapshots.
- unsubscribe_
defi_ blocks - Unsubscribes a handler from DeFi blocks.
- unsubscribe_
defi_ collects - Unsubscribes a handler from DeFi fee collects.
- unsubscribe_
defi_ flash - Unsubscribes a handler from DeFi flash loans.
- unsubscribe_
defi_ liquidity - Unsubscribes a handler from DeFi liquidity updates.
- unsubscribe_
defi_ pools - Unsubscribes a handler from DeFi pools.
- unsubscribe_
defi_ swaps - Unsubscribes a handler from DeFi pool swaps.
- unsubscribe_
funding_ rates - Unsubscribes a handler from funding rate updates.
- unsubscribe_
greeks - Unsubscribes a handler from greeks data.
- unsubscribe_
index_ prices - Unsubscribes a handler from index price updates.
- unsubscribe_
instrument_ close - Unsubscribes a handler from instrument close messages.
- unsubscribe_
instruments - Unsubscribes a handler from instrument messages.
- unsubscribe_
mark_ prices - Unsubscribes a handler from mark price updates.
- unsubscribe_
order_ events - Unsubscribes a handler from order events.
- unsubscribe_
orders - Unsubscribes a handler from orders.
- unsubscribe_
position_ events - Unsubscribes a handler from position events.
- unsubscribe_
positions - Unsubscribes a handler from positions.
- unsubscribe_
quotes - Unsubscribes a handler from quote ticks.
- unsubscribe_
trades - Unsubscribes a handler from trade ticks.