pub struct Subscription<T> { /* private fields */ }Expand description
A subscription that delivers messages from a Topic to a handler function.
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
Declares a subscription to topic.
This constructor is const so it can initialize a module-scope static.
Pass a closure returning a boxed future (|msg| Box::pin(send_welcome(msg))),
or annotate the static with
#[encore::pubsub::register] to pass send_welcome
directly and start the subscription automatically at startup.
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
Sets how long a handler has to acknowledge a message before it is redelivered (defaults to 30 seconds).
For pull subscriptions, Encore automatically extends the lease for up to 1 hour (or this duration, if longer) while the handler is running; for push subscriptions (such as GCP push), this is the delivery timeout.
Sourcepub const fn message_retention(self, _retention: Duration) -> Self
pub const fn message_retention(self, _retention: Duration) -> Self
Sets how long undelivered messages are retained before expiring (defaults to 7 days).
Sourcepub const fn min_backoff(self, _backoff: Duration) -> Self
pub const fn min_backoff(self, _backoff: Duration) -> Self
Sets the minimum retry backoff after a failed delivery (defaults to 10 seconds).
Sourcepub const fn max_backoff(self, _backoff: Duration) -> Self
pub const fn max_backoff(self, _backoff: Duration) -> Self
Sets the maximum retry backoff after a failed delivery (defaults to 10 minutes).
Sourcepub const fn max_retries(self, _retries: u32) -> Self
pub const fn max_retries(self, _retries: u32) -> Self
Sets the maximum number of retry attempts before moving a failed message
to the dead-letter queue (defaults to 100; 0 dead-letters on the first
failure).
To disable dead-lettering and retry indefinitely, use
retry_forever.
Sourcepub const fn retry_forever(self) -> Self
pub const fn retry_forever(self) -> Self
Retries failed messages indefinitely without moving them to a
dead-letter queue. Alternative to max_retries.
Sourcepub const fn max_concurrency(self, _concurrency: u32) -> Self
pub const fn max_concurrency(self, _concurrency: u32) -> Self
Limits how many messages this subscription processes concurrently (unlimited by default).
Sourcepub const fn filter(self, _filter: &'static str) -> Self
pub const fn filter(self, _filter: &'static str) -> Self
Filters which messages are delivered to this subscription based on their attributes. Unmatched messages are skipped before delivery (defaults to receiving all messages).
Uses a cloud-portable subset of the expr language:
.filter(r#"attrs.region in ["eu-west-1", "eu-north-1"] and not (attrs.kind startsWith "test-")"#)Supported operations:
- Comparisons:
attrs.region == "eu",!=,in [...],not in [...], andstartsWith "eu-"(useattrs["iana.org-lang"]for attribute names containing characters outside letters, digits, and_). - Presence checks:
"region" in attrsand"region" not in attrs. Positive value checks evaluate to false if the attribute is missing, while negated checks evaluate to true. - Boolean logic:
and(&&),or(||),not (...)(!(...)), and parentheses.
Must be a string literal so Encore can parse and validate it against cloud provider limits.
Sourcepub const fn worker(self, _worker: &'static str) -> Self
pub const fn worker(self, _worker: &'static str) -> Self
Assigns this subscription to a named worker declared in the workers
section of the service’s encore.service.json.
Only that worker process consumes messages for this subscription. If omitted, the service’s main process consumes it. Must be a string literal.
Sourcepub const fn tag(self, _key: &'static str, _value: &'static str) -> Self
pub const fn tag(self, _key: &'static str, _value: &'static str) -> Self
Attaches a key/value tag to the subscription (for example,
.tag("data", "pci")) for policy and governance tooling.
Call once per tag with unique keys. Both key and value must be string
literals so Encore can parse them statically. Keys must start with a
letter, contain only lowercase letters, digits, _, and -, and must
not start with encore (reserved for Encore’s own tags). Values use the
same character set or may be empty. Each key and value is at most 63
characters, and a subscription may have at most 32 tags.
static WELCOME: Subscription<String> =
Subscription::new(&SIGNUPS, "send-welcome", |msg| Box::pin(send_welcome(msg)))
.tag("team", "growth");Source§impl<T: Send + 'static> Subscription<T>
impl<T: Send + 'static> Subscription<T>
Auto Trait Implementations§
impl<T> !Freeze for Subscription<T>
impl<T> Forget for Subscription<T>
impl<T> Move 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