Skip to main content

FastPublisher

Struct FastPublisher 

Source
pub struct FastPublisher { /* private fields */ }
Expand description

A non-atomic, high-throughput JetStream batch publisher using the fast-ingest protocol (ADR-50, nats-server 2.14+).

Obtain via FastPublishExt::fast_publishFastPublisherBuilder::build.

A FastPublisher is Send but NOT Sync: methods require &mut self and the publisher must be driven from a single task. Dropping the publisher mid-batch is safe — the underlying async_nats::Subscriber drops with it, the server-side interest is torn down, and the server will time out the abandoned batch after 10 seconds.

Implementations§

Source§

impl FastPublisher

Source

pub fn size(&self) -> u64

Returns the number of messages added to (and published in) this batch so far, excluding any pending commit message.

Source

pub fn is_closed(&self) -> bool

Returns true if the batch has been committed, closed, or failed fatally.

Source

pub fn batch_id(&self) -> &str

Returns the batch’s inbox, which is also the batch identifier as seen by the server.

Source

pub fn gap_mode(&self) -> GapMode

Returns the currently-configured gap mode.

Source

pub fn last_ack_sequence(&self) -> u64

Returns the highest batch sequence acknowledged by the server so far. 0 before the first flow ack arrives.

Source§

impl FastPublisher

Source

pub async fn add<S: ToSubject>( &mut self, subject: S, payload: Bytes, ) -> Result<FastPubAck, FastPublishError>

Add a message to the batch with the given subject and payload.

Convenience wrapper around add_message for callers that don’t need custom headers.

Source

pub async fn add_message( &mut self, msg: OutboundMessage, ) -> Result<FastPubAck, FastPublishError>

Add a pre-constructed message to the batch.

The message’s subject, payload, and headers fields are forwarded to the server; the reply subject is always set by the publisher.

On the first call, a subscription to the batch inbox is created and the publisher waits for the initial flow ack from the server to confirm the batch has been accepted.

§Errors
Source

pub async fn commit<S: ToSubject>( self, subject: S, payload: Bytes, ) -> Result<BatchPubAck, FastPublishError>

Commit the batch by publishing a final stored message.

After this returns, the publisher is closed and no further messages can be added. The returned BatchPubAck includes the batch id (the publisher’s inbox) and the total number of messages in the batch.

Source

pub async fn commit_message( self, msg: OutboundMessage, ) -> Result<BatchPubAck, FastPublishError>

Commit the batch with a pre-constructed final message.

Source

pub async fn close(self) -> Result<BatchPubAck, FastPublishError>

End the batch without storing a final message (end-of-batch commit).

Uses the first message’s subject as the publish target; the server does not persist the commit message itself. Returns the same BatchPubAck shape as commit.

Returns FastPublishErrorKind::EmptyBatch if no messages have been added yet.

Trait Implementations§

Source§

impl Debug for FastPublisher

Source§

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

Formats the value using the given formatter. 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<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> 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 = 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