Skip to main content

RabbitMqDelivery

Struct RabbitMqDelivery 

Source
pub struct RabbitMqDelivery { /* private fields */ }
Expand description

One RabbitMQ message, decoded into an Envelope.

Exactly one of ack, retry, defer or dead_letter must be called; the trait consumes the delivery so the compiler enforces “at most once”, and an un-acked delivery is redelivered by the broker when the consumer channel closes.

retry, defer and dead_letter publish before they ack, and propagate the publish error without acking, so a failure leaves the original message unacknowledged for the broker to redeliver rather than dropping the job. Because publishes are mandatory, a missing q.dead counts as a failure. A hold queue cannot be missing: retry and defer declare it themselves, immediately before publishing, but that declaration can be refused, and retry says what happens then.

When declare_dead_letter_queues is false this backend does not own q.dead, so dead_letter rejects the message (requeue = false) instead of publishing to it, and logs why.

Trait Implementations§

Source§

impl Debug for RabbitMqDelivery

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Delivery for RabbitMqDelivery

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,

Publish first, ack second.

next is written into the hold queue for delay (declared on the spot, mandatory, waited on for a publisher confirm) and only once the broker has taken responsibility for it is the original acked. If the publish fails the ? returns before the ack, so the original stays unacknowledged and the broker redelivers it, so the job is retried rather than silently dropped. The reverse order would lose a job on any broker hiccup between the two.

The delay is rounded up to RabbitMqOptions::retry_granularity, and next returns to q at the priority it carries, 0 after Envelope::next_attempt, so it joins the back of the queue.

Three things count as that failure, and all three leave the original unacked (the worker counts a settle failure and the broker redelivers the job when the consumer channel closes):

  • the hold queue exists with different arguments, so the declaration is refused with PRECONDITION_FAILED. The declaration runs on its own channel, so concurrent publishes are untouched;
  • next.queue was never declared through this backend, so the hold queue’s durability and dead-letter target are unknown (Error::UnknownQueue);
  • delay is longer than MAX_DEFERRAL_MS (~24.8 days), which is refused rather than shortened, because a hold never releases a job early.
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,

Publish first, ack second, the same rule and the same failure modes as retry.

The delay is rounded up to RabbitMqOptions::deferred_granularity instead, and next carries its queue’s top priority, so it returns ahead of the backlog.

A caveat on “ahead of the backlog”: a consumer with prefetch N is already holding up to N messages of that backlog, and the returning deferral cannot overtake those. It is first among what is still on the queue.

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CompatExt for T

Source§

fn compat(self) -> Compat<T>
where T: Sized,

Applies the Compat adapter by value. Read more
Source§

fn compat_ref(&self) -> Compat<&T>

Applies the Compat adapter by shared reference. Read more
Source§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the Compat adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more