This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
MessageBus is an async message bus library for Rust, inspired by Actix. It enables actor-style communication between components using typed messages routed through receivers (queue implementations).
# Build the project
cargo build
# Run tests
cargo test
# Run a single test
cargo test <test_name>
# Run examples
cargo run --example demo_async
cargo run --example demo_sync_batch
cargo run --example benchmark
# Check for lints
cargo clippy
# Format code
cargo fmtThis is a Cargo workspace with three crates:
- messagebus (root) - Core message bus implementation
- crates/derive (
messagebus_derive) - Proc-macro derive implementations forMessageandErrortraits - crates/remote (
messagebus_remote) - Remote communication support using QUIC/Redis
- Bus - Central message dispatcher that routes messages to receivers based on TypeId
- Message - Trait for types that can be sent through the bus (derive with
#[derive(Message)]) - Handlers - Traits implemented by receivers to process messages
- Receivers - Queue implementations that manage message delivery
The library provides 12 handler traits for different use cases:
| Handler Type | Batched | Async |
|---|---|---|
Handler |
No | No |
AsyncHandler |
No | Yes |
BatchHandler |
Yes | No |
AsyncBatchHandler |
Yes | Yes |
| Handler Type | Batched | Async |
|---|---|---|
SynchronizedHandler |
No | No |
AsyncSynchronizedHandler |
No | Yes |
BatchSynchronizedHandler |
Yes | No |
AsyncBatchSynchronizedHandler |
Yes | Yes |
| Handler Type | Batched | Async |
|---|---|---|
LocalHandler |
No | No |
LocalAsyncHandler |
No | Yes |
LocalBatchHandler |
Yes | No |
LocalAsyncBatchHandler |
Yes | Yes |
- BufferUnorderedAsync/Sync - Concurrent message processing
- BufferUnorderedBatchedAsync/Sync - Batched concurrent processing
- SynchronizedAsync/Sync - Sequential message processing with mutable handler
- SynchronizedBatchedAsync/Sync - Batched sequential processing
Use #[derive(Message)] with attributes:
#[message(clone)]- Enable message cloning for broadcast#[message(shared)]- Enable serialization for remote transport#[type_tag("custom::name")]- Custom type tag#[namespace("my_namespace")]- Type tag namespace prefix
Messages can be sent with different routing strategies:
Broadcast- Send to all matching receivers (default)Direct(id)- Send to specific receiverExcept(id)- Send to all except specified receiverRandom/Balanced- Load distribution strategies
src/lib.rs- Bus implementation and public APIsrc/handler.rs- Handler trait definitionssrc/receiver.rs- Receiver trait and implementationsrc/builder.rs- BusBuilder for registrationsrc/envelop.rs- Message trait and TypeTagged