Skip to main content

Module msgbus

Module msgbus 

Source
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 &T directly 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::config::MessageBusConfig;
pub use self::core::MessageBus;
pub use self::core::Subscription;
pub use self::message::BusMessage;
pub use self::message::BusPayloadCategory;
pub use self::message::BusPayloadType;
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::ShareableMessageHandler;
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§

config
core
Core message bus implementation.
matching
Pattern matching for message bus topic subscriptions.
message
mstr
Type-safe string wrappers for message bus patterns, topics, and endpoints.
stubs
switchboard
Built-in message bus endpoint, topic, and pattern names.
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.

Structs§

SuppressExternalGuard
Guard that prevents republished external messages from being forwarded again.

Traits§

BusTap
Observes dispatched bus traffic for the durable event store.
MessageBusBacking
External message bus backing facade.
MessageBusBackingFactory
Factory for constructing external message bus backings.
MessageBusExternalEgress
External egress surface for serialized message bus publications.
MessageBusExternalIngress
External ingress surface for serialized message bus publications.

Functions§

clear_bus_tap
Clears the registered bus tap on this thread.
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.
exact_subscriber_count_funding_rates
Returns the exact subscriber count for funding rates on a topic, excluding wildcard pattern subscriptions.
exact_subscriber_count_index_prices
Returns the exact subscriber count for index prices on a topic, excluding wildcard pattern subscriptions.
exact_subscriber_count_mark_prices
Returns the exact subscriber count for mark prices on a topic, excluding wildcard pattern subscriptions.
exact_subscriber_count_option_greeks
Returns the exact subscriber count for option greeks on a topic, excluding wildcard pattern subscriptions.
exact_subscriber_count_quotes
Returns the exact subscriber count for quotes on a topic, excluding wildcard pattern subscriptions.
exact_subscriber_count_trades
Returns the exact subscriber count for trades on a topic, excluding wildcard pattern subscriptions.
external_egress_from_backing
Wraps a message bus backing for external egress installation.
external_io_from_backing
Splits a message bus backing into external egress and ingress surfaces.
get_message_bus
Gets the thread-local message bus.
has_endpoint
Returns whether an endpoint handler is registered for the given endpoint name.
has_quote_endpoint
Returns whether a quote tick handler is registered for the given endpoint.
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_instrument
Publishes an instrument to subscribers on a topic.
publish_mark_price
Publishes a mark price update to subscribers on a topic.
publish_option_chain
Publishes an option chain slice to subscribers on a topic.
publish_option_greeks
Publishes option greeks to subscribers on a topic.
publish_order_event
Publishes an order event to subscribers on a topic.
publish_portfolio_snapshot
Publishes a portfolio snapshot 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.
republish_external_message
Decodes an externally-received BusMessage and republishes it onto the internal bus.
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 DataResponse to 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_bus_tap
Registers tap as the thread-local bus tap, replacing any previously installed tap.
set_message_bus
Sets the thread-local message bus, replacing any existing one.
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_option_chain
Subscribes a handler to option chain slice updates matching a pattern.
subscribe_option_greeks
Subscribes a handler to option greeks updates matching a pattern.
subscribe_order_events
Subscribes a handler to order events matching a pattern.
subscribe_portfolio_snapshot
Subscribes a handler to portfolio snapshots 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.
try_get_message_bus
Returns the thread-local message bus if one has been set for this thread.
try_publish_any
Tries to publish a message to the current thread’s registered message bus.
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_option_chain
Unsubscribes a handler from option chain slice updates.
unsubscribe_option_greeks
Unsubscribes a handler from option greeks updates.
unsubscribe_order_events
Unsubscribes a handler from order events.
unsubscribe_orders
Unsubscribes a handler from orders.
unsubscribe_portfolio_snapshot
Unsubscribes a handler from portfolio snapshots.
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.

Type Aliases§

MessageBusExternalReceiver
Receiver for external message bus ingress publications.