Skip to main content

NatsMessage

Enum NatsMessage 

Source
pub enum NatsMessage {
    Core(Box<CoreMessage>),
    JetStream(Box<JetStreamMessage>),
}
Expand description

A NATS delivery. Two flavours: core NATS (no ack) and JetStream (real ack/nack/redelivery).

Both variants are boxed to keep the enum compact; the wrapped async_nats messages are large.

Variants§

§

Core(Box<CoreMessage>)

A core NATS subject delivery. Acknowledgement is not supported.

§

JetStream(Box<JetStreamMessage>)

A JetStream pull-consumer delivery with full ack support.

Trait Implementations§

Source§

impl BuildContext<NatsMessage> for JetStreamContext

Source§

fn build(msg: &NatsMessage) -> Self

Builds the context value by reading fields out of msg.
Source§

impl Debug for NatsMessage

Source§

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

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

impl IncomingMessage for NatsMessage

Source§

fn partition_key(&self) -> Option<&[u8]>

The PARTITION_KEY_HEADER value the sender set, which the runtime’s keyed worker lanes (workers(n, by_key)) order by.

Source§

fn redelivery_count(&self) -> Option<u64>

How many times the server has delivered this message, counting this one.

A JetStream consumer keeps that count and reports it on every delivery, so a cap declared at the mount site counts the server’s own redeliveries - an ack_wait that ran out, a negative acknowledgement - and not only the copies this process published. Core NATS neither stores a message nor redelivers one, so a core delivery has no count and the framework’s retry-count header is the whole tally.

Source§

fn supports_nack_after(&self) -> bool

Whether this delivery can honor a native delayed redelivery.

true for every JetStream delivery: the protocol carries the delay in the negative acknowledgement itself, so no opt-in infrastructure is needed. Core NATS has no acknowledgement at all, so a core delivery reports false and the runtime applies its broker-agnostic deferred re-publish instead.

Source§

async fn nack_after(self, delay: Duration) -> Result<(), AckError>

Redelivers this message no sooner than delay, natively: JetStream’s negative acknowledgement takes the delay as its argument (-NAK {"delay": ns}), so the server holds the message for that long and then redelivers it on this consumer. Nothing is re-published and no copy is made, so the delivery count, the stream sequence, and the payload all stay the ones the message was first delivered with.

§Errors

Returns AckError::Unsupported on a core (non-JetStream) delivery, and AckError::Broker when the acknowledgement cannot be sent.

Source§

fn payload(&self) -> &[u8] ⓘ

Returns the raw payload of the message.
Source§

fn headers(&self) -> &HeaderMap

Returns the headers attached to the message.
Source§

async fn ack(self) -> Result<(), AckError>

Acknowledges successful processing. Consumes the message handle. Read more
Source§

async fn nack(self, requeue: bool) -> Result<(), AckError>

Negatively acknowledges the message. When requeue is true the broker should redeliver according to its own retry policy; when false it should drop or dead-letter the message. Read more
Source§

impl Partitioned for NatsMessage

Partitioned lets the workers(N, by_key) runtime feature assign a dispatch lane based on a well-known message header. NATS has no native partition concept, so the key travels as the PARTITION_KEY_HEADER header value and the sender is responsible for setting it.

Source§

fn partition_key(&self) -> Option<&[u8]>

Returns the partition key for this item, or None if the broker should pick a partition.

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PublishedThrough<DefaultSlot> for T

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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