Expand description
§RustRabbit
A high-performance, production-ready RabbitMQ client library for Rust with advanced observability, resilience, and performance features.
§Features
- 🚀 Performance: Message batching and connection pooling for high throughput
- 🔍 Observability: Comprehensive Prometheus metrics and health monitoring
- 🛡️ Resilience: Circuit breaker pattern and graceful shutdown handling
- ⚙️ Developer Experience: Builder pattern APIs and type-safe message handling
§Quick Start
use rust_rabbit::{RustRabbit, RabbitConfig};
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct OrderMessage {
order_id: String,
amount: f64,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create configuration
let config = RabbitConfig::builder()
.connection_string("amqp://localhost:5672")
.build();
// Create RustRabbit instance
let rabbit = RustRabbit::new(config).await?;
// Publish message
let publisher = rabbit.publisher();
let order = OrderMessage {
order_id: "ORD-12345".to_string(),
amount: 99.99,
};
publisher.publish_to_queue("orders", &order, None).await?;
Ok(())
}§Advanced Features
§Prometheus Metrics
Enable comprehensive metrics collection:
use rust_rabbit::{RustRabbit, RabbitConfig, metrics::RustRabbitMetrics};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let metrics = RustRabbitMetrics::new()?;
let config = RabbitConfig::default();
let rabbit = RustRabbit::with_metrics(config, metrics).await?;
Ok(())
}§Message Batching
For high-throughput scenarios:
use rust_rabbit::{RustRabbit, batching::BatchConfig};
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let rabbit = RustRabbit::new(RabbitConfig::default()).await?;
let batch_config = BatchConfig::builder()
.max_batch_size(100)
.flush_interval(Duration::from_millis(500))
.build();
let batcher = rabbit.create_batcher(batch_config).await?;
Ok(())
}§Graceful Shutdown
Handle shutdown signals properly:
use rust_rabbit::{RustRabbit, shutdown::ShutdownConfig};
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut rabbit = RustRabbit::new(RabbitConfig::default()).await?;
let shutdown_config = ShutdownConfig::builder()
.pending_timeout(Duration::from_secs(30))
.build();
let _shutdown_manager = rabbit.enable_shutdown_handling(shutdown_config);
Ok(())
}Re-exports§
pub use batching::BatchConfig;pub use batching::BatchConfigBuilder;pub use batching::MessageBatcher;pub use circuit_breaker::CircuitBreaker;pub use circuit_breaker::CircuitBreakerConfig;pub use circuit_breaker::CircuitBreakerStats;pub use circuit_breaker::CircuitState;pub use config::HealthCheckConfig;pub use config::HealthCheckConfigBuilder;pub use config::PoolConfig;pub use config::PoolConfigBuilder;pub use config::RabbitConfig;pub use config::RabbitConfigBuilder;pub use config::RetryConfig;pub use config::RetryConfigBuilder;pub use connection::Connection;pub use connection::ConnectionManager;pub use connection::ConnectionStats;pub use consumer::Consumer;pub use consumer::ConsumerOptions;pub use consumer::ConsumerOptionsBuilder;pub use consumer::MessageHandler;pub use error::RabbitError;pub use error::Result;pub use health::ConnectionStatus;pub use health::HealthChecker;pub use metrics::MetricsTimer;pub use metrics::RustRabbitMetrics;pub use publisher::CustomExchangeDeclareOptions;pub use publisher::CustomQueueDeclareOptions;pub use publisher::PublishOptions;pub use publisher::PublishOptionsBuilder;pub use publisher::Publisher;pub use retry::DelayedMessageExchange;pub use retry::RetryPolicy;pub use shutdown::setup_signal_handling;pub use shutdown::ShutdownConfig;pub use shutdown::ShutdownHandler;pub use shutdown::ShutdownManager;pub use shutdown::ShutdownSignal;
Modules§
- batching
- Message batching implementation for high-throughput scenarios
- circuit_
breaker - Circuit breaker implementation for connection resilience
- config
- connection
- consumer
- error
- health
- metrics
- Metrics and observability module for RustRabbit
- publisher
- retry
- shutdown
- Graceful shutdown handling for RustRabbit
Structs§
- Rust
Rabbit - Main facade for the rust-rabbit library