pub struct StreamBatchContext { /* private fields */ }Expand description
Batch context for a batched Redis Streams subscription: what the whole subscription shares.
The runtime builds one per dispatched batch from the batch’s first delivery, and a batch body
reads it by keys key with ctx.context(..). Per-delivery data (the entry id, the position
that redelivers one entry) has no place here, because a batch spans many deliveries: it rides
the batch’s own elements instead, read off each element’s typed header contract. Keeping this a
separate type from StreamContext is what rejects a batch body asking for per-delivery fields
at compile time.
§Examples
use ruststream_fred::stream::prelude::*;
/// A batch that saw the poison marker rewinds the group once the batch is settled.
#[subscriber(RedisStream::new("orders").group("workers"))]
async fn work(
batch: &[Order],
ctx: &mut Context<'_, StreamBatchContext>,
) -> HandlerOutcome {
if batch.iter().any(|order| order.id == 0)
&& ctx
.context(keys::SeekHandle)
.seek(RedisGroupPosition::beginning())
.await
.is_err()
{
return HandlerOutcome::retry();
}
HandlerOutcome::ack()
}Implementations§
Source§impl StreamBatchContext
impl StreamBatchContext
Sourcepub fn consumer_group(&self) -> &str
pub fn consumer_group(&self) -> &str
The consumer group every delivery of this batch was read through.
Sourcepub const fn seeker(&self) -> &RedisGroupSeeker
pub const fn seeker(&self) -> &RedisGroupSeeker
The handle repositioning this subscription’s consumer group.
Trait Implementations§
Source§impl BuildBatchContext<RedisMessage> for StreamBatchContext
impl BuildBatchContext<RedisMessage> for StreamBatchContext
Source§fn build(first: &RedisMessage) -> Self
fn build(first: &RedisMessage) -> Self
Builds the context value by reading subscription-scoped fields out of the batch’s first
delivery, or out of the batch itself where it lends its values as one slice.
Source§impl Clone for StreamBatchContext
impl Clone for StreamBatchContext
Source§impl Debug for StreamBatchContext
impl Debug for StreamBatchContext
Source§impl Field<StreamBatchContext> for FredPool
impl Field<StreamBatchContext> for FredPool
Source§impl Field<StreamBatchContext> for SeekHandle
impl Field<StreamBatchContext> for SeekHandle
Source§type Value<'a> = &'a RedisGroupSeeker
type Value<'a> = &'a RedisGroupSeeker
The value read through this key, borrowed from the source for
'a.Source§fn get(self, src: &StreamBatchContext) -> &RedisGroupSeeker
fn get(self, src: &StreamBatchContext) -> &RedisGroupSeeker
Reads this key’s field out of
src.Source§impl Field<StreamBatchContext> for ConsumerGroup
impl Field<StreamBatchContext> for ConsumerGroup
Auto Trait Implementations§
impl !RefUnwindSafe for StreamBatchContext
impl !UnwindSafe for StreamBatchContext
impl Freeze for StreamBatchContext
impl Send for StreamBatchContext
impl Sync for StreamBatchContext
impl Unpin for StreamBatchContext
impl UnsafeUnpin for StreamBatchContext
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
Mutably borrows from an owned value. Read more
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<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> ⓘ
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 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> ⓘ
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