pub enum DelayStrategy {
TTL,
DelayedExchange,
}Expand description
Strategy for delaying retry messages
§TTL (Time-To-Live) Strategy
Uses RabbitMQ’s TTL feature with temporary retry queues. Messages are published to temporary queues that expire and route to the original queue. Pros: No plugin required, simple setup Cons: Less precise timing, requires queue cleanup
§DelayedExchange Strategy
Uses the RabbitMQ delayed message exchange plugin (requires x-delayed-message plugin). Messages are published to a delay exchange with x-delay header. The exchange automatically routes messages after the delay period. Pros: More precise, cleaner architecture, single exchange Cons: Requires RabbitMQ plugin installation
§Example
use rust_rabbit::retry::{DelayStrategy, RetryConfig, RetryMechanism};
use std::time::Duration;
// Using TTL strategy (default, no plugin required)
let config = RetryConfig {
max_retries: 3,
mechanism: RetryMechanism::Exponential {
base_delay: Duration::from_secs(1),
max_delay: Duration::from_secs(60),
},
delay_strategy: DelayStrategy::TTL,
dead_letter_exchange: None,
dead_letter_queue: None,
};
// Using RabbitMQ delayed exchange plugin (requires plugin)
let config = RetryConfig {
max_retries: 3,
mechanism: RetryMechanism::Linear { delay: Duration::from_secs(5) },
delay_strategy: DelayStrategy::DelayedExchange,
dead_letter_exchange: None,
dead_letter_queue: None,
};Variants§
TTL
TTL-based delays using temporary queues (no plugin required)
DelayedExchange
RabbitMQ delayed message exchange plugin (requires x-delayed-message plugin)
⚠️ IMPORTANT: Using this strategy without the rabbitmq_delayed_message_exchange plugin
will cause your application to crash with “NOT_FOUND - operation not permitted on this exchange” error.
Before deploying code with DelayedExchange, ensure:
- Plugin is installed: https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases
- Plugin is enabled:
rabbitmq-plugins enable rabbitmq_delayed_message_exchange - RabbitMQ is restarted after plugin installation
Trait Implementations§
Source§impl Clone for DelayStrategy
impl Clone for DelayStrategy
Source§fn clone(&self) -> DelayStrategy
fn clone(&self) -> DelayStrategy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more