Skip to main content

Delivery

Trait Delivery 

Source
pub trait Delivery: Send + 'static {
    // Required methods
    fn envelope(&self) -> &Envelope;
    fn ack<'async_trait>(
        self: Box<Self>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait;
    fn dead_letter<'life0, 'async_trait>(
        self: Box<Self>,
        reason: &'life0 str,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn retry<'async_trait>(
        self: Box<Self>,
        next: Envelope,
        delay: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait;
    fn defer<'async_trait>(
        self: Box<Self>,
        next: Envelope,
        delay: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait;
}
Expand description

A message received from the broker. Must be acked or nacked exactly once.

Required Methods§

Source

fn envelope(&self) -> &Envelope

The message this delivery carries.

Source

fn ack<'async_trait>( self: Box<Self>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,

Successfully processed; remove from broker.

Source

fn dead_letter<'life0, 'async_trait>( self: Box<Self>, reason: &'life0 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Failed permanently (or attempts exhausted); route to dead-letter storage.

Source

fn retry<'async_trait>( self: Box<Self>, next: Envelope, delay: Duration, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,

Failed transiently; schedule next (already attempt + 1) to be redelivered after delay. Implementations must ack the original after the retry is durably scheduled so no message is lost.

Source

fn defer<'async_trait>( self: Box<Self>, next: Envelope, delay: Duration, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,

Did not fail, but must run again in delay: durably schedule next (already deferrals + 1 with its priority set, attempt unchanged) to reappear on next.queue, then ack the original.

Same “publish before ack” rule as Delivery::retry: if the scheduling fails, the original must be left unacked so the broker redelivers it.

How the message is held is backend-specific (a dedicated hold queue per delay on RabbitMQ, a timer in MemoryBackend), but the observable contract is the same: nothing is delivered before delay has passed, and when it comes back it carries next.priority, so it overtakes normally enqueued work on a queue that supports priorities. See crate::JobError::Deferred.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§