#[non_exhaustive]pub enum FailurePolicy {
FailFast,
Drop,
Retry,
RetryAfter(Duration),
Skip,
}Expand description
What a subscriber does when it cannot process a message.
Set per subscriber, separately for a handler panic and for a decode failure, with the
#[subscriber(.., on_failure(panic = .., decode = ..))] clause. Each maps onto a settlement
of the offending message, except FailFast, which tears the service down so
an orchestrator restarts it.
§Examples
use std::time::Duration;
use ruststream::prelude::*;
use serde::Deserialize;
#[derive(Deserialize)]
struct Order {
id: u64,
}
/// A schema change rolls out producer-first: a payload this version cannot read yet comes
/// back in a minute rather than being dropped.
#[subscriber("orders", on_failure(decode = retry_after(Duration::from_secs(60))))]
async fn accept(order: &Order) -> HandlerOutcome {
tracing::info!(order.id, "accepted");
HandlerOutcome::ack()
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
FailFast
Log a loud error naming the subscription, then initiate a graceful app shutdown and make
run return Err, so an orchestrator restarts the service and
the failure lands in the logs. The default for a handler panic. Only takes effect under an
unwinding panic profile; with panic = "abort" the process is already gone and there is
nothing to catch.
Drop
Drop the message: nack(false). The broker discards or dead-letters it. The default for a
decode failure - one malformed payload should not stop the consumer.
Retry
Requeue the message: nack(true). Useful when the failure is transient (a dependency not
yet available, a schema not yet propagated).
RetryAfter(Duration)
Requeue the message, but ask the broker to redeliver no sooner than the given delay:
nack_after(..). A broker without native delayed redelivery takes the copy the runtime
publishes instead - see
HandlerOutcome::retry_after.
Skip
Acknowledge the failed message to move past it: ack. A deliberate poison-message escape
hatch - it advances past a message that could not be processed. This is not success; the
message is gone and was never handled.
Trait Implementations§
Source§impl Clone for FailurePolicy
impl Clone for FailurePolicy
Source§fn clone(&self) -> FailurePolicy
fn clone(&self) -> FailurePolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for FailurePolicy
Source§impl Debug for FailurePolicy
impl Debug for FailurePolicy
impl Eq for FailurePolicy
Source§impl PartialEq for FailurePolicy
impl PartialEq for FailurePolicy
impl StructuralPartialEq for FailurePolicy
Auto Trait Implementations§
impl Freeze for FailurePolicy
impl RefUnwindSafe for FailurePolicy
impl Send for FailurePolicy
impl Sync for FailurePolicy
impl Unpin for FailurePolicy
impl UnsafeUnpin for FailurePolicy
impl UnwindSafe for FailurePolicy
Blanket Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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