Skip to main content

SubscribeOptions

Struct SubscribeOptions 

Source
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

Source

pub fn new(subject: impl Into<String>) -> Self

Constructs a fresh Core NATS subscription options set for subject.

Source

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.

Source

pub fn jetstream(self, stream: impl Into<String>) -> Self

Switches the subscription to a JetStream pull-consumer backed by the named stream.

Source

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.

Source

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.

Source

pub const fn ack_wait(self, ack_wait: Duration) -> Self

Per-message acknowledgement timeout. After this window an unacked delivery is redelivered.

Source

pub const fn max_ack_pending(self, max: i64) -> Self

Soft cap on in-flight unacked deliveries.

Source

pub const fn deliver_policy(self, policy: DeliverPolicy) -> Self

JetStream delivery starting position. Defaults to DeliverPolicy::All when unset.

Source

pub fn subject(&self) -> &str

The subject pattern this subscription will receive messages on.

Source

pub const fn is_jetstream(&self) -> bool

True when Self::jetstream has been set.

Source

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_group is set together with jetstream (queue groups are Core-only);
  • any JetStream-only field (durable, ack_wait, max_ack_pending, deliver_policy, filter_subject) is set without jetstream.

Trait Implementations§

Source§

impl Clone for SubscribeOptions

Source§

fn clone(&self) -> SubscribeOptions

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SubscribeOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl SubscriptionSource<NatsBroker> for SubscribeOptions

Source§

type Subscriber = NatsSubscriber

The subscriber type this source opens.
Source§

fn name(&self) -> &str

The name (subject / channel) this subscription binds to. Read more
Source§

async fn subscribe( self, broker: &NatsBroker, ) -> Result<Self::Subscriber, NatsError>

Opens the subscription against broker. Called once, after Broker::connect. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more