docs.rs failed to build revoke-mq-0.3.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
revoke-mq
Message queue client module for the Revoke microservices framework, providing unified abstractions for multiple message queue backends.
Features
- Multiple Backends: Support for Redis, Kafka, RabbitMQ, and NATS
- Unified Interface: Common trait-based API across all implementations
- Async Support: Built on Tokio for high-performance async operations
- Connection Pooling: Efficient connection management
- Error Handling: Comprehensive error handling with retry support
- Message Patterns: Pub/Sub, Queue, and Topic patterns
- Serialization: Built-in support for JSON, MessagePack, and Protobuf
Installation
Add to your Cargo.toml:
[]
= { = "0.1", = ["redis", "kafka"] }
Feature Flags
memory: In-memory queue for testing (default)redis: Redis Pub/Sub and Streams supportkafka: Apache Kafka supportrabbitmq: RabbitMQ supportnats: NATS messaging supportfull: Enable all backends
Quick Start
Basic Usage
use ;
use MessageQueue as MQTrait;
async
Backend Implementations
Memory Queue
In-memory implementation for testing:
use MemoryQueue;
let queue = new;
// Publish
queue.publish.await?;
// Subscribe
let mut stream = queue.subscribe.await?;
Redis
Redis Pub/Sub and Streams:
use ;
let config = RedisConfig ;
let queue = new.await?;
Kafka
Apache Kafka producer and consumer:
use ;
let config = KafkaConfig ;
let queue = new.await?;
// Produce with key
queue.publish_with_key.await?;
RabbitMQ
AMQP 0.9.1 support:
use ;
let config = RabbitConfig ;
let queue = new.await?;
// Declare queue
queue.declare_queue.await?;
// Publish to exchange
queue.publish_to_exchange.await?;
NATS
NATS messaging and JetStream:
use ;
let config = NatsConfig ;
let queue = new.await?;
// Create stream
queue.create_stream.await?;
Message Patterns
Publish/Subscribe
// Publisher
mq.publish.await?;
// Subscriber
let mut stream = mq.subscribe.await?;
while let Some = stream.next.await
Work Queue
// Producer
for i in 0..100
// Worker
let mut stream = mq.subscribe.await?;
while let Some = stream.next.await
Request/Reply
use RequestReply;
// Server
let rr = new;
rr.serve.await?;
// Client
let result = rr.request.await?;
println!;
Advanced Features
Message Headers
use Message;
let message = new
.with_header
.with_header
.with_ttl;
mq.publish_message.await?;
Message Serialization
use ;
// Publish
let event = Event ;
mq.publish_json.await?;
// Subscribe
let mut stream = mq..await?;
while let Some = stream.next.await
Connection Resilience
use ResilientQueue;
let queue = new
.with_retry_policy
.with_circuit_breaker
.build;
// Automatic retry and circuit breaking
queue.publish.await?;
Batch Operations
// Batch publish
let messages = vec!;
mq.publish_batch.await?;
// Batch consume
let mut stream = mq.subscribe.await?;
let batch = stream.take..await;
Performance Tuning
Connection Pooling
let config = RedisConfig ;
Prefetching
// RabbitMQ prefetch
let config = RabbitConfig ;
// Kafka consumer config
let config = KafkaConfig ;
Monitoring
Metrics
use QueueMetrics;
let metrics = new;
// Get metrics
let stats = metrics.get_stats.await?;
println!;
println!;
println!;
Health Checks
use HealthCheck;
let health = new;
match health.check.await
Error Handling
use Error;
match mq.publish.await
Best Practices
- Connection Management: Use connection pooling for better performance
- Error Handling: Always handle connection and queue full errors
- Message Size: Keep messages small; use object storage for large data
- Acknowledgment: Ensure proper message acknowledgment in work queues
- Monitoring: Track queue depth and consumer lag
- Serialization: Use efficient formats like MessagePack for high throughput
- Patterns: Choose the right pattern (pub/sub vs queue) for your use case
Examples
See the examples directory:
basic_pubsub.rs- Simple publish/subscribework_queue.rs- Task distribution patternrequest_reply.rs- RPC over message queuestreaming.rs- High-throughput streaming