pub struct NatsSubscriber { /* private fields */ }Expand description
A NATS subscription.
Backed transparently by either a Core subscription (no ack) or a JetStream pull consumer
(full ack/nack/term). Construct via crate::NatsBroker::subscribe with
crate::SubscribeOptions.
Trait Implementations§
Source§impl BatchSubscriber for NatsSubscriber
impl BatchSubscriber for NatsSubscriber
Source§fn batches(
&mut self,
) -> impl Stream<Item = Result<Self::Batch, Self::Error>> + Send + '_
fn batches( &mut self, ) -> impl Stream<Item = Result<Self::Batch, Self::Error>> + Send + '_
Returns a stream of message batches.
JetStream batches natively: one stream item is one fetch of up to
pull_batch messages, waiting at most
pull_expires before delivering a partial batch
(an empty fetch is retried, so the stream never yields empty batches). Core NATS has no
wire-level batching; there a batch is whatever the client has already buffered locally
(at least one message, at most [CORE_BATCH_LIMIT]), with no added latency.
Drive a subscriber through either Subscriber::stream or batches, not both at once:
on JetStream each issues its own pull requests, so deliveries would be split between
them.
§Cancel safety
Dropping the returned stream between items is allowed. On JetStream, dropping it
mid-fetch can leave already-fetched, undelivered messages to be redelivered after the
consumer’s ack_wait.
Source§type Batch = Vec<NatsMessage>
type Batch = Vec<NatsMessage>
batches. Implementations choose between Vec, custom
iterators, or anything else that yields the underlying Subscriber::Message.