pub struct ProcessingTimeoutMiddleware { /* private fields */ }Expand description
Middleware that enforces a processing timeout on message handling.
This middleware wraps message processing with tokio::time::timeout to ensure
that messages don’t exceed a maximum processing time. If processing exceeds the
timeout, the message is negative-acknowledged (nacked) with requeue before the
broker’s consumer timeout can kill the connection.
§Why This Matters
Message brokers like RabbitMQ have consumer timeouts (default 30 seconds). If a worker receives a message but doesn’t ack/nack within that window, the broker assumes the consumer is dead and closes the channel with a PRECONDITION_FAILED error.
This middleware prevents that by enforcing a timeout shorter than the broker’s timeout, ensuring graceful nack with proper error handling.
§Example
use foxtive_worker::ProcessingTimeoutMiddleware;
use std::time::Duration;
// Enforce 25-second timeout (less than RabbitMQ's 30s default)
let middleware = ProcessingTimeoutMiddleware::new(Duration::from_secs(25));§Architecture
The middleware uses tokio::time::timeout which does NOT spawn detached tasks.
It runs the future inline and cancels it if the timeout expires. This maintains
controlled concurrency without unbounded task spawning.
Message → [Timeout Check] → [Next Handler] → Result
↓ (if timeout)
Nack + ErrorImplementations§
Trait Implementations§
Source§impl Clone for ProcessingTimeoutMiddleware
impl Clone for ProcessingTimeoutMiddleware
Source§fn clone(&self) -> ProcessingTimeoutMiddleware
fn clone(&self) -> ProcessingTimeoutMiddleware
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more