pub struct Subscription<T> { /* private fields */ }Expand description
A subscription to a topic: every message published to the topic is handed to its handler.
Implementations§
Source§impl<T> Subscription<T>
impl<T> Subscription<T>
Sourcepub const fn new<E: Encoding<T>, O>(
topic: &'static Topic<T, E, O>,
name: &'static str,
handler: Handler<T>,
) -> Self
pub const fn new<E: Encoding<T>, O>( topic: &'static Topic<T, E, O>, name: &'static str, handler: Handler<T>, ) -> Self
Declare a subscription to topic. const so it can initialize a
module-scope static.
The handler is a function, boxing the future that handles a message:
|msg| Box::pin(send_welcome(msg)). Under
#[encore::pubsub::register], which also has
the subscription started with the app, it can be just send_welcome.
Options follow, each a method of its own:
static WELCOME: Subscription<String> =
Subscription::new(&SIGNUPS, "send-welcome", |msg| Box::pin(send_welcome(msg)))
.ack_deadline(Duration::from_secs(60))
.max_retries(5);Sourcepub const fn ack_deadline(self, _deadline: Duration) -> Self
pub const fn ack_deadline(self, _deadline: Duration) -> Self
How long the handler has to finish before the message is delivered again. 30 seconds if not given.
The options are part of the declaration, read by Encore’s parser: each
takes the subscription by value, so it cannot be called on the static.
Sourcepub const fn message_retention(self, _retention: Duration) -> Self
pub const fn message_retention(self, _retention: Duration) -> Self
How long an undelivered message is kept. Seven days if not given.
Sourcepub const fn min_backoff(self, _backoff: Duration) -> Self
pub const fn min_backoff(self, _backoff: Duration) -> Self
The shortest wait before a failed message is delivered again. 10 seconds if not given.
Sourcepub const fn max_backoff(self, _backoff: Duration) -> Self
pub const fn max_backoff(self, _backoff: Duration) -> Self
The longest wait before a failed message is delivered again. 10 minutes if not given.
Sourcepub const fn max_retries(self, _retries: i32) -> Self
pub const fn max_retries(self, _retries: i32) -> Self
How many times a failed message is delivered again before it is given up on. 100 if not given; -1 to never give up, -2 to never retry.
Sourcepub const fn max_concurrency(self, _concurrency: u32) -> Self
pub const fn max_concurrency(self, _concurrency: u32) -> Self
How many messages are handled at once. Unlimited if not given.
Source§impl<T: Send + 'static> Subscription<T>
impl<T: Send + 'static> Subscription<T>
Auto Trait Implementations§
impl<T> !Freeze for Subscription<T>
impl<T> RefUnwindSafe for Subscription<T>
impl<T> Send for Subscription<T>
impl<T> Sync for Subscription<T>
impl<T> Unpin for Subscription<T>
impl<T> UnsafeUnpin for Subscription<T>
impl<T> UnwindSafe for Subscription<T>
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request