Skip to main content

Reader

Struct Reader 

Source
pub struct Reader<C: ConsumerApi = Consumer> { /* private fields */ }
Expand description

Reader handle — a non-durable consumer that reads from a topic without persisting an acknowledgement cursor. Use a reader for: log replay, message inspection, batch ETL, or anywhere you want at-most-once delivery semantics that the broker doesn’t track.

Generic over C: ConsumerApi per ADR-0026 §D1. The default (C = magnetar_runtime_tokio::Consumer) keeps existing callers — including magnetar::Reader (no type argument) — pointing at the tokio specialisation. Moonpool callers name Reader<magnetar_runtime_moonpool::Consumer<P>> directly.

Implementations§

Source§

impl<C: ConsumerApi> Reader<C>

Source

pub async fn read_next(&self) -> Result<IncomingMessage, PulsarError>

Block until the next message arrives. Identical to Java Reader#readNext. Internally also stamps the returned id into the per-reader cursor so a subsequent Self::has_message_available call asks the broker the right question.

§Errors
  • PulsarError::Other (with the runtime’s error stringified) on broker rejection or wire failure.
Source

pub fn record_received(&self, message_id: MessageId)

Manually record a received message id into the per-reader cursor. Useful when callers go through engine-specific receive paths directly and still want Self::has_message_available to behave correctly.

Source

pub async fn has_message_available(&self) -> Result<bool, PulsarError>

true if the broker has at least one message strictly past the most-recently returned message id. Mirrors Java Reader#hasMessageAvailable (no argument — the reader tracks its own cursor). Returns true for fresh readers (no read_next yet) if the broker reports any non-empty topic.

§Errors
Source

pub fn consumer(&self) -> &C

Borrow the underlying consumer for advanced operations not covered by crate::ConsumerApi (close, seek, flow, etc.).

Source

pub fn topic(&self) -> String

Topic this reader is bound to. Mirrors Java Reader#getTopic.

Source

pub fn subscription(&self) -> String

Auto-generated subscription name behind this reader. Mirrors Java Reader#getSubscriptionName.

Source

pub async fn last_message_id(&self) -> Result<MessageId, PulsarError>

Ask the broker for the topic’s last-published message id. Mirrors Java Reader#getLastMessageId.

§Errors
Source

pub async fn has_message_after( &self, cursor: MessageId, ) -> Result<bool, PulsarError>

true if the broker has at least one message strictly past the supplied cursor. Mirrors Java Reader#hasMessageAvailable (the Reader form takes no cursor; pass the last id you received).

§Errors
Source§

impl Reader<Consumer>

Tokio-engine-specific Reader methods that touch types not on the engine-agnostic crate::ConsumerApi surface — the tokio ReceiveFut, tokio::time::timeout, Consumer::close(self), and seek_to_earliest.

Source

pub async fn read_next_with_timeout( &self, timeout: Duration, ) -> Result<Option<IncomingMessage>, PulsarError>

Same as Self::read_next but bounded by timeout. Returns Ok(None) when the deadline elapses with no message. Mirrors Java Reader#readNext(int timeout, TimeUnit unit).

Source

pub fn read_next_fut(&self) -> ReceiveFut

Returns the raw magnetar_runtime_tokio::ReceiveFut without per-reader cursor tracking. Use this when integrating with a custom select loop where you want cancel-safe receive futures; pair with Self::record_received if you still want has_message_available to work.

Source

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

Close the reader.

Source

pub async fn seek_to_earliest(&self) -> Result<(), PulsarError>

Seek the reader to the earliest available message. Mirrors Java Reader#seek(MessageId.earliest).

Source

pub async fn seek_to_latest(&self) -> Result<(), PulsarError>

Seek the reader to the latest (head) position. Mirrors Java Reader#seek(MessageId.latest).

Source

pub async fn seek_to_message( &self, message_id: MessageId, ) -> Result<(), PulsarError>

Seek the reader to a specific message id. Mirrors Java Reader#seek(MessageId).

Source

pub async fn seek_to_timestamp( &self, publish_time_ms: u64, ) -> Result<(), PulsarError>

Seek the reader to a publish-time deadline (millis since UNIX epoch). Mirrors Java Reader#seek(long).

Source

pub fn is_connected(&self) -> bool

Mirrors org.apache.pulsar.client.api.Reader#isConnected.

Source

pub fn last_disconnected_timestamp(&self) -> Option<SystemTime>

Mirrors org.apache.pulsar.client.api.Reader#getLastDisconnectedTimestamp.

Source

pub fn stats(&self) -> ConsumerStats

Mirrors org.apache.pulsar.client.api.Reader#getStats.

Source

pub fn has_reached_end_of_topic(&self) -> bool

true once the broker has signalled (via CommandReachedEndOfTopic) that no more messages will be dispatched on this topic. Mirrors Java Reader#hasReachedEndOfTopic.

Source

pub fn pause(&self)

Pause delivery for this reader. The broker stops dispatching new messages once already-issued permits drain; buffered messages remain available via Self::read_next. Mirrors Reader#pause.

Source

pub fn resume(&self)

Resume delivery after Self::pause. Mirrors Reader#resume.

Source

pub fn is_inactive(&self) -> bool

true when the reader has been disconnected longer than the configured “inactive” threshold. Mirrors Java Reader#isInactive (returns the underlying consumer’s inactivity state since readers wrap an Exclusive subscription).

Source

pub fn is_closed(&self) -> bool

true once the reader’s underlying subscription has been closed locally or by the broker. Mirrors Java Reader#isClosed.

Source

pub fn available_in_queue(&self) -> usize

Number of messages currently buffered in the reader’s receiver queue, waiting for a read_next call to pull them out. Mirrors Java Reader#getNumOfPendingMessages semantics.

Source

pub fn available_permits(&self) -> u32

Number of dispatch permits the broker still holds un-spent for this reader — grants issued, minus one per dispatch unit that has actually arrived. Issue #414 re-pointed this from the purely-additive grant mirror to the real decrementing balance, so the value moves under dispatch (ADR-0101 amending ADR-0082).

Source

pub fn has_received_any_message(&self) -> bool

true if the reader has received at least one message since opening. Mirrors Java Reader#hasReceivedAnyMessage.

Trait Implementations§

Source§

impl<C: Debug + ConsumerApi> Debug for Reader<C>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C = Consumer> !Freeze for Reader<C>

§

impl<C = Consumer> !RefUnwindSafe for Reader<C>

§

impl<C> Send for Reader<C>

§

impl<C> Sync for Reader<C>

§

impl<C> Unpin for Reader<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for Reader<C>
where C: UnsafeUnpin,

§

impl<C> UnwindSafe for Reader<C>
where C: UnwindSafe,

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 = !

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<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