pub struct SubscribeOptions { /* private fields */ }Expand description
Builder describing one subscription against crate::NatsBroker (or its test counterpart).
Core NATS is the default. Calling SubscribeOptions::jetstream switches to a JetStream
pull-consumer; remaining JetStream-only fields (durable name, ack wait, max ack pending,
deliver policy, filter subject) only take effect when jetstream(_) was called and are
rejected otherwise.
§Examples
use std::time::Duration;
use ruststream_nats::SubscribeOptions;
// Core NATS subscription with a queue group.
let core = SubscribeOptions::new("orders.*").queue_group("workers");
// JetStream pull consumer.
let js = SubscribeOptions::new("orders.*")
.jetstream("ORDERS")
.durable("worker-1")
.ack_wait(Duration::from_secs(30));Implementations§
Source§impl SubscribeOptions
impl SubscribeOptions
Sourcepub fn new(subject: impl Into<String>) -> Self
pub fn new(subject: impl Into<String>) -> Self
Constructs a fresh Core NATS subscription options set for subject.
Sourcepub fn queue_group(self, name: impl Into<String>) -> Self
pub fn queue_group(self, name: impl Into<String>) -> Self
Sets the Core NATS queue group used for load-balanced delivery. Mutually exclusive with
Self::jetstream.
Sourcepub fn jetstream(self, stream: impl Into<String>) -> Self
pub fn jetstream(self, stream: impl Into<String>) -> Self
Switches the subscription to a JetStream pull-consumer backed by the named stream.
Sourcepub fn durable(self, name: impl Into<String>) -> Self
pub fn durable(self, name: impl Into<String>) -> Self
Marks the JetStream consumer as durable under the given name. Without this the
consumer is ephemeral and discarded when the subscriber drops.
Sourcepub fn filter_subject(self, subject: impl Into<String>) -> Self
pub fn filter_subject(self, subject: impl Into<String>) -> Self
Narrows which subjects of the parent JetStream stream this consumer reads. Defaults to
Self::subject when not set.
Sourcepub const fn ack_wait(self, ack_wait: Duration) -> Self
pub const fn ack_wait(self, ack_wait: Duration) -> Self
Per-message acknowledgement timeout. After this window an unacked delivery is redelivered.
Sourcepub const fn max_ack_pending(self, max: i64) -> Self
pub const fn max_ack_pending(self, max: i64) -> Self
Soft cap on in-flight unacked deliveries.
Sourcepub const fn deliver_policy(self, policy: DeliverPolicy) -> Self
pub const fn deliver_policy(self, policy: DeliverPolicy) -> Self
JetStream delivery starting position. Defaults to DeliverPolicy::All when unset.
Sourcepub const fn is_jetstream(&self) -> bool
pub const fn is_jetstream(&self) -> bool
True when Self::jetstream has been set.
Sourcepub fn validate(&self) -> Result<(), NatsError>
pub fn validate(&self) -> Result<(), NatsError>
Rejects combinations the broker cannot honour. Called by every subscribe
implementation before any work.
§Errors
Returns NatsError::InvalidOptions when:
queue_groupis set together withjetstream(queue groups are Core-only);- any
JetStream-only field (durable,ack_wait,max_ack_pending,deliver_policy,filter_subject) is set withoutjetstream.
Trait Implementations§
Source§impl Clone for SubscribeOptions
impl Clone for SubscribeOptions
Source§fn clone(&self) -> SubscribeOptions
fn clone(&self) -> SubscribeOptions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more