pub struct RedisPubSub { /* private fields */ }Expand description
Describes one Pub/Sub subscription on a single channel, against a ConnectedRedisBroker.
A glob is RedisPubSubPattern instead.
§Examples
use ruststream_fred::pubsub::prelude::*;
use serde::Deserialize;
#[derive(Deserialize)]
struct Event {
kind: String,
}
// Classic: `SUBSCRIBE`, broadcast to every node of a cluster.
#[subscriber(RedisPubSub::new("events"))]
async fn on_event(event: &Event) -> HandlerOutcome {
tracing::info!(event.kind, "event");
HandlerOutcome::ack()
}
// Sharded: `SSUBSCRIBE`, served by the node that owns the channel's slot.
#[subscriber(RedisPubSub::new("metrics").mode(PubSubMode::Sharded))]
async fn on_metric(event: &Event) -> HandlerOutcome {
tracing::info!(event.kind, "metric");
HandlerOutcome::ack()
}
#[ruststream::app]
fn app() -> impl App {
RustStream::new(AppInfo::new("events", "0.1.0")).with_broker(
RedisBroker::cluster(["10.0.0.1:6379"]),
|b| {
b.include(on_event);
b.include(on_metric);
},
)
}Implementations§
Source§impl RedisPubSub
impl RedisPubSub
Sourcepub const fn mode(self, mode: PubSubMode) -> Self
pub const fn mode(self, mode: PubSubMode) -> Self
Sets the delivery mode. Defaults to PubSubMode::Classic.
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(RedisPubSub::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 RedisPubSub
impl Clone for RedisPubSub
Source§impl Debug for RedisPubSub
impl Debug for RedisPubSub
Source§impl IntoSource for RedisPubSub
impl IntoSource for RedisPubSub
Source§type Source = RedisPubSub
type Source = RedisPubSub
Source§fn into_source(self) -> Self
fn into_source(self) -> Self
Source§impl RedeliveryAddressed<ConnectedRedisBroker> for RedisPubSub
The channel itself.
impl RedeliveryAddressed<ConnectedRedisBroker> for RedisPubSub
The channel itself.
The answer is about the address, not about the command: reaching a
PubSubMode::Sharded subscription still takes a publisher in the same mode, which is the
policy the mount site names with out_retry.
Source§fn redelivery_address(
&self,
_connected: &ConnectedRedisBroker,
) -> impl Future<Output = Result<RedeliveryAddress, RedisError>>
fn redelivery_address( &self, _connected: &ConnectedRedisBroker, ) -> impl Future<Output = Result<RedeliveryAddress, RedisError>>
Source§impl SubscriptionSource<ConnectedRedisBroker> for RedisPubSub
impl SubscriptionSource<ConnectedRedisBroker> for RedisPubSub
Source§type Copies = AddressedCopies
type Copies = AddressedCopies
Pub/Sub cannot acknowledge, so every retry is a copy this process publishes, and the channel is where it goes.
Source§type Subscriber = RedisPubSubSubscriber
type Subscriber = RedisPubSubSubscriber
Source§fn declare_retry(self, declaration: &RetryDeclaration) -> Self
fn declare_retry(self, declaration: &RetryDeclaration) -> Self
Source§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_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 RedisPubSub
impl !UnwindSafe for RedisPubSub
impl Freeze for RedisPubSub
impl Send for RedisPubSub
impl Sync for RedisPubSub
impl Unpin for RedisPubSub
impl UnsafeUnpin for RedisPubSub
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