pub struct RedisPubSubPattern { /* private fields */ }Expand description
Describes one Pub/Sub subscription on a glob pattern (PSUBSCRIBE), against a
ConnectedRedisBroker.
Patterns are classic-only: sharded Pub/Sub routes by slot and has no PSUBSCRIBE, so this
descriptor carries no mode to get wrong.
§Examples
use ruststream_fred::pubsub::prelude::*;
use serde::Deserialize;
#[derive(Deserialize)]
struct Event {
kind: String,
}
#[subscriber(RedisPubSubPattern::new("events.*"))]
async fn on_any_event(event: &Event, Ctx(channel): Ctx<keys::Channel>) -> HandlerOutcome {
tracing::info!(event.kind, channel, "event");
HandlerOutcome::ack()
}
#[ruststream::app]
fn app() -> impl App {
RustStream::new(AppInfo::new("events", "0.1.0")).with_broker(
RedisBroker::standalone("redis://localhost:6379"),
|b| {
// A glob is no channel a `PUBLISH` can name, so the mount site says where a
// retry copy goes.
b.include(on_any_event)
.out_retry(Publish::default())
.to("events.retry");
},
)
}Sharded Pub/Sub has no pattern subscription, so a pattern takes no mode:
use ruststream_fred::{PubSubMode, RedisPubSubPattern};
let events = RedisPubSubPattern::new("events.*").mode(PubSubMode::Sharded);Implementations§
Source§impl RedisPubSubPattern
impl RedisPubSubPattern
Sourcepub fn new(pattern: impl Into<String>) -> Self
pub fn new(pattern: impl Into<String>) -> Self
A subscription on every channel matching the glob pattern.
Sourcepub fn codec(self, codec: impl Codec + 'static) -> Self
pub fn codec(self, codec: impl Codec + 'static) -> Self
Decodes the header/payload envelope with codec (must match the publisher). Without it the
default binary framing is used. Either way the payload arrives as it was published.
Sourcepub const fn buffer(self, messages: NonZeroUsize) -> Self
pub const fn buffer(self, messages: NonZeroUsize) -> Self
Sets how many messages the subscription holds that its handler has not taken yet.
Redis pushes a Pub/Sub message the moment it is published, and the subscription keeps it
until the handler asks for the next one. The buffer bounds how many may wait. Once it is
full, each new message drops the oldest, and the subscription logs a warning with the
channel and the count it lost. The default is fred’s own
(PerformanceConfig::broadcast_channel_capacity, 32 messages in fred 10.1).
Raise it for a handler that falls behind bursts: set it to the largest burst the handler
must absorb. The room is reserved when the subscription opens, about 600 bytes per message
of buffer whatever the payloads weigh, because fred sizes all eight of a client’s
notification channels by it.
§Examples
use ruststream::nonzero;
use ruststream_fred::pubsub::prelude::*;
// A handler that falls behind a burst of up to ten thousand events loses none of them.
#[subscriber(RedisPubSubPattern::new("events.*").buffer(nonzero!(10_000)))]
async fn on_event(event: &Event) -> HandlerOutcome {
tracing::info!(event.kind, "event");
HandlerOutcome::ack()
}Trait Implementations§
Source§impl Clone for RedisPubSubPattern
impl Clone for RedisPubSubPattern
Source§impl Debug for RedisPubSubPattern
impl Debug for RedisPubSubPattern
Source§impl IntoSource for RedisPubSubPattern
impl IntoSource for RedisPubSubPattern
Source§type Source = RedisPubSubPattern
type Source = RedisPubSubPattern
Source§fn into_source(self) -> Self
fn into_source(self) -> Self
Source§impl SubscriptionSource<ConnectedRedisBroker> for RedisPubSubPattern
A pattern subscription reads every channel the glob matches, and a glob is not a channel a
PUBLISH can name, so the mount site names where a retry copy goes: .out_retry(policy).to(..)
for a fixed channel, or a transform that reads the delivery’s own channel.
impl SubscriptionSource<ConnectedRedisBroker> for RedisPubSubPattern
A pattern subscription reads every channel the glob matches, and a glob is not a channel a
PUBLISH can name, so the mount site names where a retry copy goes: .out_retry(policy).to(..)
for a fixed channel, or a transform that reads the delivery’s own channel.
Source§type Subscriber = RedisPubSubSubscriber
type Subscriber = RedisPubSubSubscriber
Source§type Copies = NamedCopies
type Copies = NamedCopies
AddressedCopies, NamedCopies or BrokerMoves. Read moreSource§async fn subscribe(
self,
connected: &ConnectedRedisBroker,
) -> Result<Self::Subscriber, RedisError>
async fn subscribe( self, connected: &ConnectedRedisBroker, ) -> Result<Self::Subscriber, RedisError>
Source§fn channel_bindings(&self) -> Bindings
fn channel_bindings(&self) -> Bindings
AsyncAPI document. Read moreSource§fn declare_retry(self, declaration: &RetryDeclaration) -> Selfwhere
Self: Sized,
fn declare_retry(self, declaration: &RetryDeclaration) -> Selfwhere
Self: Sized,
Source§fn declare_retry_on(
&self,
connected: &C,
declaration: &RetryDeclaration,
) -> Result<(), DeclareRetryError>
fn declare_retry_on( &self, connected: &C, declaration: &RetryDeclaration, ) -> Result<(), DeclareRetryError>
Source§fn operation_bindings(&self) -> Bindings
fn operation_bindings(&self) -> Bindings
receive operation in the document. Read moreSource§fn message_bindings(&self) -> Bindings
fn message_bindings(&self) -> Bindings
Auto Trait Implementations§
impl !RefUnwindSafe for RedisPubSubPattern
impl !UnwindSafe for RedisPubSubPattern
impl Freeze for RedisPubSubPattern
impl Send for RedisPubSubPattern
impl Sync for RedisPubSubPattern
impl Unpin for RedisPubSubPattern
impl UnsafeUnpin for RedisPubSubPattern
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<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