Comprehensive examples demonstrating how to use RocketMQ-Rust client APIs and features.
This is a standalone project containing practical examples for RocketMQ-Rust. It showcases various usage patterns including:
- Consumer Examples: Push consumer, pop consumer, message listeners
- Producer Examples: (Coming soon)
- Admin Operations: (Coming soon)
- Rust 1.85.0 or later
- Running RocketMQ nameserver and broker (default:
127.0.0.1:9876)
# Navigate to the examples directory
cd rocketmq-example
# Run the pop consumer example
cargo run --example pop-consumer
# List all available examples
cargo run --example <TAB>Demonstrates how to consume messages in cluster mode with load balancing across multiple consumer instances.
File: examples/consumer/consumer_cluster.rs
Run:
cargo run --example consumer-clusterFeatures:
- Cluster mode consumption (default mode)
- Load balancing across consumer instances
- Concurrent message processing
- Each message consumed by only one instance
Demonstrates how to use the pop consumption model with client-side load balancing disabled.
File: examples/consumer/pop_consumer.rs
Run:
cargo run --example pop-consumerFeatures:
- Pop-based message consumption
- Concurrent message processing
- Automatic topic/consumer group creation
- Message request mode configuration
Most examples use default configuration:
const NAMESRV_ADDR: &str = "127.0.0.1:9876";
const TOPIC: &str = "TopicTest";
const CONSUMER_GROUP: &str = "please_rename_unique_group_name_4";Modify these constants in the example source files to match your RocketMQ cluster setup.
- Create a new file in the appropriate category folder (e.g.,
examples/consumer/my_example.rs) - Add the example configuration to
Cargo.toml:
[[example]]
name = "my-example"
path = "examples/consumer/my_example.rs"- Run the example:
cargo run --example my-exampleThis project references local RocketMQ-Rust crates:
rocketmq-client-rust- Client APIsrocketmq-common- Common utilitiesrocketmq-rust- Core runtimerocketmq-tools- Admin tools
rocketmq-example/
โโโ examples/
โ โโโ consumer/
โ โโโ consumer_cluster.rs
โ โโโ pop_consumer.rs
โโโ Cargo.toml
โโโ README.md
- This is a standalone project, not part of the main RocketMQ-Rust workspace
- Examples use relative path dependencies to reference parent crates
- Each example is self-contained and runnable independently
Contributions of new examples are welcome! Please ensure:
- Examples are well-documented with inline comments
- Configuration is clearly specified
- Examples follow Rust best practices
- Each example demonstrates a single, clear use case
This project inherits the dual-license from RocketMQ-Rust:
- Apache License 2.0
- MIT License