Skip to main content

RedisStream

Struct RedisStream 

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

Describes one Redis Streams subscription against crate::RedisBroker.

§Examples

use std::time::Duration;
use ruststream_fred::RedisStream;

// Fresh tail: a normal worker reading new entries.
let fresh = RedisStream::new("orders").group("workers").count(128);

// Recovery: reclaim entries a crashed worker left pending for over 30s.
let recover = RedisStream::reclaim("orders", Duration::from_secs(30)).group("workers");

Implementations§

Source§

impl RedisStream

Source

pub fn new(key: impl Into<String>) -> Self

A fresh-tail subscription on key: reads new entries via XREADGROUP >.

A consumer group is required; set it with group.

Source

pub fn reclaim(key: impl Into<String>, min_idle: Duration) -> Self

A recovery subscription on key: reclaims pending entries idle at least min_idle via XAUTOCLAIM. Run it alongside a new subscriber on the same group to pick up messages a consumer fetched but died before acking.

min_idle has no default and must exceed the longest legitimate handler runtime: set it too low and a healthy consumer’s in-flight message gets reclaimed and processed twice.

Source

pub fn group(self, group: impl Into<String>) -> Self

Sets the consumer group. Required for every subscription.

Source

pub fn consumer(self, consumer: impl Into<String>) -> Self

Sets this consumer’s name within the group. Defaults to an auto-generated unique name.

Source

pub const fn count(self, count: u64) -> Self

Upper bound on entries fetched per read. Defaults to 64.

Source

pub const fn block(self, block: Duration) -> Self

How long one read blocks waiting for entries. Defaults to 5 seconds. In fresh-tail mode this is the XREADGROUP server-side block; in reclaim mode XAUTOCLAIM does not block, so this is the poll interval slept between scans that find nothing to reclaim.

Source

pub fn start_id(self, start: StreamStart) -> Self

Where a newly created group starts reading. Ignored if the group already exists. Only meaningful for the fresh-tail new mode.

Source

pub fn dead_letter(self, key: impl Into<String>) -> Self

Routes dropped and poison messages to the named dead-letter stream instead of discarding them. Off by default. The copy is tagged with DEAD_LETTER_REASON_HEADER. See [crate::deadletter].

Source

pub const fn max_deliveries(self, max: u64) -> Self

Caps how many times a message may be delivered before it is treated as poison (dead-lettered or, with no dead-letter stream, discarded). Off by default.

The cap is checked against both the framework retry-count header (the nack/republish loop) and the native stream delivery count (the reclaim loop), so a message poisoning either way is caught.

Source

pub fn delayed_retry(self, retry: DelayedRetry) -> Self

Opts this subscription into durable, crash-safe delayed retry backed by a ZSET delay queue.

Off by default: without it, retry_after(delay) / nack_after(delay) degrade to the runtime’s broker-agnostic deferred re-publish (at-most-once over the delay window). With it, a delayed delivery is ZADDed to the named ZSET and replayed from there once due, so the retry survives a process crash. See DelayedRetry for the key and TTL requirements.

The sweeper that replays due entries runs inside this subscription’s read loop, so its granularity is the read block interval.

Source

pub fn key(&self) -> &str

The stream key this subscription reads.

Trait Implementations§

Source§

impl Clone for RedisStream

Source§

fn clone(&self) -> RedisStream

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RedisStream

Source§

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

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

impl SubscriptionSource<RedisBroker> for RedisStream

Source§

type Subscriber = RedisSubscriber

The subscriber type this source opens.
Source§

fn name(&self) -> &str

The name (subject / channel) this subscription binds to. Read more
Source§

async fn subscribe( self, broker: &RedisBroker, ) -> Result<Self::Subscriber, RedisError>

Opens the subscription against broker. Called once, after Broker::connect. Read more

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<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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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