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.
rabbit_warren 🐇
A robust, ergonomic, and production-ready RabbitMQ client library for Rust, built on top of lapin.
It abstracts away typical boilerplate (Publisher Confirms, the mandatory flag, automatic ack/nack strategies, and distributed tracing), allowing developers to focus purely on business logic.
Features
- Safe Publishing: Automatically enables Publisher Confirms and uses the
mandatoryflag to detect unroutable messages. - Smart Consuming: Automatic
ackon success. On error, you declaratively choose the strategy:Requeue(with built-in backoff to prevent infinite retry loops) orDiscard. - Distributed Tracing: Built-in OpenTelemetry context propagation (injecting/extracting trace headers from AMQP properties).
- Zero Boilerplate: No need to manually manage channels, ackers, or nack options in your application code.
- JSON Helpers: Built-in
publish_jsonanddeserialize_deliveryutilities.
Installation
Add this to your Cargo.toml:
[]
= "0.1" # Replace with the latest version
= { = "1", = ["full"] }
= { = "1.0", = ["derive"] }
Note: You do not need to add lapin to your Cargo.toml. All necessary types (e.g., Delivery, FieldTable) are re-exported by this crate.
Usage Examples
1. Initialization
use RmqClient;
async
2. Publishing Messages
use Serialize;
async
3. Consuming Messages
The library provides a ResultExt trait, allowing you to declaratively specify what should happen upon an error, without cluttering your handler with ack/nack logic.
use ;
use Deserialize;
async
4. Ergonomic Error Handling (ResultExt)
You can use extension methods directly in your call chain to explicitly dictate the message's fate on specific errors:
use ;
client.consume;
5. Consumer Refactoring: Before vs. After
This library replaces dozens of lines of manual channel management, while let loops, and explicit ack/nack calls with pure business logic.
Before raw lapin boilerplate
// 1. Verbose topology declaration
channel.exchange_declare.await?;
channel.queue_declare.await?;
channel.queue_bind.await?;
let mut consumer = channel.basic_consume.await?;
// 2. Manual lifecycle and stream management
spawn;
After using rabbit_warren
First, centrally define the error handling strategy for your app:
use ;
Then, write clean, business-focused consumer code:
let handler = move |delivery: Delivery| ;
// The library handles the loop, tracing, and ack/nack automatically
rmq_client.consume;
Custom Ack Strategies
If your application has a custom error enum, implement IntoAckAction to centralize retry logic:
use ;
Note: By default, any error type not implementing IntoAckAction is treated as AckAction::Requeue to prevent accidental data loss.
Distributed Tracing
The library integrates seamlessly with the tracing ecosystem. The consume method automatically creates an info_span for every message.
For full OpenTelemetry support, extract and inject context into AMQP headers:
use FieldTable;
use global;
let mut headers = default;
get_text_map_propagator;
client.publish_json.await?;
Testing
Integration tests use testcontainers to spin up an ephemeral RabbitMQ instance. Ensure you have Docker installed and running, then execute:
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.