#[non_exhaustive]pub enum Delay {
DlxTtl {
waiting_queue: Option<String>,
},
DelayedMessageExchange {
exchange: Option<String>,
},
}Expand description
How a subscription handles retry_after / nack_after delays.
Passed to RabbitQueue::delay. A waiting queue or a delayed
exchange is infrastructure the user owns, so a subscription opts in explicitly.
§Examples
use std::time::Duration;
use ruststream_lapin::prelude::*;
use serde::Deserialize;
#[derive(Deserialize)]
struct Order {
id: u64,
paid: bool,
}
// An unpaid order waits a minute in `orders.retry` on the broker, then comes back here.
#[subscriber(RabbitQueue::new("orders").delay(Delay::dlx_ttl()))]
async fn fulfil(order: &Order) -> HandlerOutcome {
if !order.paid {
return HandlerOutcome::retry_after(Duration::from_mins(1));
}
tracing::info!(order.id, "fulfilling");
HandlerOutcome::ack()
}
fn app() -> RustStream {
let broker = LapinBroker::new("amqp://localhost:5672").declare_topology(true);
RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(broker, |b| {
b.include(fulfil);
})
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
DlxTtl
Route delayed redeliveries through a TTL waiting queue whose dead-letter target is the origin queue.
§Mixed delays
A queue releases expired messages only from its head, classic and quorum queues alike, so a
short-TTL message behind a long-TTL one waits for the long one. When delays vary widely, use
one waiting queue per delay class (dlx_ttl_named), or the
delayed-message-exchange plugin (Delay::plugin_dme, feature plugin-dme), where a short
delay never waits behind a long one.
DelayedMessageExchange
Route delayed redeliveries through the
rabbitmq_delayed_message_exchange
plugin: the message is re-published to an x-delayed-message exchange with an x-delay
header, and the plugin releases it to the origin queue after the delay. Unlike a waiting
queue, mixed delays do not block each other. Requires the plugin on the broker, so
it is behind the plugin-dme feature.
Implementations§
Source§impl Delay
impl Delay
Sourcepub fn dlx_ttl_named(name: impl Into<String>) -> Self
pub fn dlx_ttl_named(name: impl Into<String>) -> Self
A TTL waiting queue with an explicit name.
Sourcepub const fn plugin_dme() -> Self
pub const fn plugin_dme() -> Self
A delayed-message-exchange named <origin>.delay.
Sourcepub fn plugin_dme_named(name: impl Into<String>) -> Self
pub fn plugin_dme_named(name: impl Into<String>) -> Self
A delayed-message-exchange with an explicit name (share one across queues if you like).
Trait Implementations§
impl Eq for Delay
impl StructuralPartialEq for Delay
Auto Trait Implementations§
impl Freeze for Delay
impl RefUnwindSafe for Delay
impl Send for Delay
impl Sync for Delay
impl Unpin for Delay
impl UnsafeUnpin for Delay
impl UnwindSafe for Delay
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more