pub struct JetStreamSubject { /* private fields */ }Expand description
A subject read through a JetStream pull consumer on one stream.
The consumer is created when the subscription opens. Name it with durable
and the server keeps its position across restarts; leave the name out and the consumer is
ephemeral, discarded when the subscriber drops.
§Examples
use ruststream_nats::prelude::*;
use serde::Deserialize;
#[derive(Deserialize)]
struct Order {
id: u64,
}
// The durable keeps its position across restarts, and every replica shares it.
#[subscriber(
JetStreamSubject::new("orders.*", "ORDERS")
.durable("billing")
.ack_wait(NonZeroDuration::from_secs(nonzero!(30)))
)]
async fn bill(order: &Order) -> HandlerOutcome {
tracing::info!(order.id, "billed");
HandlerOutcome::ack()
}
#[ruststream::app]
fn app() -> impl App {
RustStream::new(AppInfo::new("billing", "0.1.0")).with_broker(
NatsBroker::new("nats://localhost:4222"),
|b| {
b.include(bill);
},
)
}A queue group is Core NATS only, so it is not a method here:
use ruststream_nats::JetStreamSubject;
let bad = JetStreamSubject::new("orders.*", "ORDERS").queue_group("workers");Implementations§
Source§impl JetStreamSubject
impl JetStreamSubject
Sourcepub fn new(subject: impl Into<String>, stream: impl Into<String>) -> Self
pub fn new(subject: impl Into<String>, stream: impl Into<String>) -> Self
Reads subject from the stream named stream.
subject is the pattern the subscription reports and the default consumer filter;
stream is the JetStream stream that stores it.
Sourcepub fn durable(self, name: impl Into<String>) -> Self
pub fn durable(self, name: impl Into<String>) -> Self
Names the consumer, so the server keeps its position across restarts.
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 stream this consumer reads. Defaults to the subject the constructor named.
Sourcepub const fn ack_wait(self, ack_wait: NonZeroDuration) -> Self
pub const fn ack_wait(self, ack_wait: NonZeroDuration) -> Self
Per-message acknowledgement timeout. After this window an unacked delivery is redelivered. Defaults to 30 seconds.
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. Defaults to 1024.
Sourcepub const fn deliver_policy(self, policy: DeliverPolicy) -> Self
pub const fn deliver_policy(self, policy: DeliverPolicy) -> Self
Where a newly created consumer starts reading. Defaults to DeliverPolicy::All.
Sourcepub const fn pull_expires(self, expires: NonZeroDuration) -> Self
pub const fn pull_expires(self, expires: NonZeroDuration) -> Self
How long one fetch waits before delivering a partial (or retrying an empty) batch.
Defaults to 5 seconds. Has no effect on the per-message
Subscriber::stream path.
How many messages a batch carries is not set here: the batch size travels with the
registration (b.include(handler.batch(nonzero!(6)))) and reaches the fetch as the
argument of BatchSubscriber::batches.
Trait Implementations§
Source§impl Clone for JetStreamSubject
impl Clone for JetStreamSubject
Source§impl Debug for JetStreamSubject
impl Debug for JetStreamSubject
Source§impl IntoSource for JetStreamSubject
impl IntoSource for JetStreamSubject
Source§type Source = JetStreamSubject
type Source = JetStreamSubject
Source§fn into_source(self) -> Self
fn into_source(self) -> Self
Source§impl NatsSubscription for JetStreamSubject
impl NatsSubscription for JetStreamSubject
Source§fn ensure_subject(&self) -> Result<(), NatsError>
fn ensure_subject(&self) -> Result<(), NatsError>
#[subscriber(..)] attribute writes, so it cannot hand back a Result. Every
subscribe implementation calls this before it does any work. Read moreSource§impl RedeliveryAddressed<ConnectedNatsBroker> for JetStreamSubject
The consumer’s filter subject, which defaults to the subject the descriptor names.
impl RedeliveryAddressed<ConnectedNatsBroker> for JetStreamSubject
The consumer’s filter subject, which defaults to the subject the descriptor names.
A JetStream consumer holds a delivery itself and takes the delay in its negative
acknowledgement, so the framework publishes no copy here and this address is what the
conformance suite checks rather than what a running service uses. A consumer filtering a
pattern reports that pattern, which is not a publish destination; nothing publishes to it, and
a .to(name) at the mount site overrides it.
Source§fn redelivery_address(
&self,
_connected: &ConnectedNatsBroker,
) -> impl Future<Output = Result<RedeliveryAddress, NatsError>> + Send
fn redelivery_address( &self, _connected: &ConnectedNatsBroker, ) -> impl Future<Output = Result<RedeliveryAddress, NatsError>> + Send
Source§impl SubscriptionSource<ConnectedNatsBroker> for JetStreamSubject
impl SubscriptionSource<ConnectedNatsBroker> for JetStreamSubject
Source§type Subscriber = NatsSubscriber
type Subscriber = NatsSubscriber
Source§type Copies = AddressedCopies
type Copies = AddressedCopies
AddressedCopies, NamedCopies or BrokerMoves. Read moreSource§async fn subscribe(
self,
connected: &ConnectedNatsBroker,
) -> Result<Self::Subscriber, NatsError>
async fn subscribe( self, connected: &ConnectedNatsBroker, ) -> Result<Self::Subscriber, NatsError>
Source§fn channel_bindings(&self) -> Bindings
fn channel_bindings(&self) -> Bindings
AsyncAPI document. Read moreSource§fn declare_retry(self, declaration: &RetryDeclaration) -> Selfwhere
Self: Sized,
fn declare_retry(self, declaration: &RetryDeclaration) -> Selfwhere
Self: Sized,
Source§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 Freeze for JetStreamSubject
impl RefUnwindSafe for JetStreamSubject
impl Send for JetStreamSubject
impl Sync for JetStreamSubject
impl Unpin for JetStreamSubject
impl UnsafeUnpin for JetStreamSubject
impl UnwindSafe for JetStreamSubject
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