Skip to main content

TypedConsumer

Struct TypedConsumer 

Source
pub struct TypedConsumer<S: Schema, C: ConsumerApi = Consumer> { /* private fields */ }
Expand description

A schema-aware consumer. Wraps a consumer and decodes every received payload with the configured schema before returning to the caller.

Generic over C: ConsumerApi per ADR-0026 §D1. The default (C = magnetar_runtime_tokio::Consumer) keeps existing callers — magnetar::TypedConsumer<S> without a consumer type argument — pointing at the tokio specialisation. Moonpool callers name TypedConsumer<S, magnetar_runtime_moonpool::Consumer<P>>.

Engine-generic methods dispatch through crate::ConsumerApi. Methods that require the runtime’s magnetar_proto::IncomingMessage shape (the receive family, receive_batch, reconsume_later, republish_dead_letters) or helpers not on ConsumerApi today (pause, resume, flow, is_paused, has_reached_end_of_topic, available_in_queue, available_permits, has_received_any_message, is_inactive, ack_batch, ack_with_properties, ack_cumulative_with_properties, ack_batch_with_txn, seek_to_message, seek_to_timestamp, receive_batch_with_bytes_cap, drain_dead_letter, unsubscribe with force=true) stay on the tokio specialisation impl TypedConsumer<S, magnetar_runtime_tokio::Consumer> until the trait grows them.

Implementations§

Source§

impl<S: Schema, C: ConsumerApi> TypedConsumer<S, C>

Source

pub fn inner(&self) -> &C

The inner runtime consumer.

Source

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

Acknowledge a single message.

Source

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

Close the underlying consumer.

Source

pub fn topic(&self) -> String

Topic this consumer is bound to. Mirrors Java Consumer#getTopic.

Source

pub fn subscription(&self) -> String

Subscription name. Mirrors Java Consumer#getSubscription.

Source

pub fn name(&self) -> String

Consumer name. Mirrors Java Consumer#getConsumerName.

Source

pub fn is_connected(&self) -> bool

true while the broker connection is up. Mirrors Java Consumer#isConnected.

Source

pub fn is_closed(&self) -> bool

true once Self::close / unsubscribe has completed.

Source

pub fn stats(&self) -> ConsumerStats

Cumulative consumer counters snapshot. Mirrors Java Consumer#getStats.

Source

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

Wall-clock instant of the most-recent connection drop. Mirrors Java Consumer#getLastDisconnectedTimestamp.

Source

pub fn negative_ack(&self, message_id: MessageId)

Negative-ack a message. Mirrors Java Consumer#negativeAcknowledge.

Source

pub fn redeliver_unacked(&self)

Tell the broker to redeliver every unacked message. Mirrors Java Consumer#redeliverUnacknowledgedMessages.

Source

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

Cumulative ack. Mirrors Java Consumer#acknowledgeCumulativeAsync(MessageId).

Source

pub fn ack_grouped(&self, message_id: MessageId)

Fire-and-forget ack into the consumer’s ack-grouping tracker (opt-in via TypedConsumerBuilder::ack_group_time).

Source

pub fn ack_grouped_cumulative(&self, message_id: MessageId)

Fire-and-forget cumulative ack into the consumer’s ack-grouping tracker.

Source

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

Ack a single message inside a transaction. Mirrors Java Consumer#acknowledgeAsync(MessageId, Transaction).

Source

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

Cumulative ack inside a transaction. Mirrors Java Consumer#acknowledgeCumulativeAsync(MessageId, Transaction).

Source

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

Seek to the earliest message. Mirrors Java Consumer#seek(MessageId.earliest).

Source

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

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

Source

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

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

Source

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

true if the broker has at least one message strictly past cursor. Mirrors Java Consumer#hasMessageAvailable (the variant taking a cursor).

Source§

impl<S: Schema> TypedConsumer<S, Consumer>

Tokio-engine-specific TypedConsumer methods.

These methods depend on either (a) the runtime’s magnetar_proto::IncomingMessage shape (the receive family returns the proto-level message so the consumer keeps access to single_metadata + arrived_at — fields the engine-generic crate::ConsumerApi::receive trait method drops by widening to crate::IncomingMessage), or (b) Consumer helpers not yet on crate::ConsumerApi (the long tail of pause / flow / the extended ack family / DLQ / retry / batched receive). Each of these methods can be lifted into the engine-generic impl block as the matching helper lands on the trait — same incremental split as PartitionedProducer<P>.

Source

pub async fn receive(&self) -> Result<TypedMessage<S>, PulsarError>

Receive the next message. The payload is schema-decoded; if decoding fails the error is surfaced as PulsarError::Schema and the message remains unacked so the broker re-delivers it (subject to the consumer’s redelivery policy).

PIP-87 AutoConsumeSchema consumers transparently fetch the broker-registered schema on first call via Schema::needs_broker_schema + Schema::store_resolved_schema. Subsequent receives reuse the cache. A broker-side schema-lookup failure surfaces as PulsarError::Client with magnetar_runtime_tokio::ClientError::Broker.

Source

pub fn pause(&self)

Pause delivery. Mirrors Java Consumer#pause.

Source

pub fn resume(&self)

Resume delivery. Mirrors Java Consumer#resume.

Source

pub fn is_paused(&self) -> bool

true after Self::pause until Self::resume. Mirrors Java Consumer#isPaused semantics.

Source

pub fn has_reached_end_of_topic(&self) -> bool

true once the broker has signalled end-of-topic. Mirrors Java Consumer#hasReachedEndOfTopic.

Source

pub fn available_in_queue(&self) -> usize

Buffered message count. Mirrors Java Consumer#getNumMessagesInQueue.

Source

pub fn available_permits(&self) -> u32

Outstanding broker permits — grants issued, minus one per dispatch unit that has actually arrived. Mirrors Java ConsumerBase#getAvailablePermits. 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 this consumer has received at least one message since opening. Mirrors Java Consumer#hasReceivedAnyMessage.

Source

pub fn is_inactive(&self) -> bool

true when the consumer has been disconnected longer than the configured inactive threshold. Mirrors Java Consumer#isInactive semantics.

Source

pub async fn ack_batch( &self, message_ids: Vec<MessageId>, ) -> Result<(), PulsarError>

Batched individual ack. Mirrors Java Consumer#acknowledgeAsync(List<MessageId>).

Source

pub async fn unsubscribe(&self, force: bool) -> Result<(), PulsarError>

Unsubscribe this consumer’s subscription from the broker. Mirrors Java Consumer#unsubscribe. force=true (PIP-313) drops the subscription even when other consumers are still attached to the same subscription name.

Source

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

Seek to a specific message id. Mirrors Java Consumer#seek(MessageId).

Source

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

Seek to a publish-time deadline (millis since epoch). Mirrors Java Consumer#seek(long).

Source

pub fn flow(&self, permits: u32)

Issue an explicit FLOW (permit refill). Mirrors ConsumerBase#increaseAvailablePermits.

Source

pub async fn receive_with_timeout( &self, timeout: Duration, ) -> Result<Option<TypedMessage<S>>, PulsarError>

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

Source

pub async fn receive_batch( &self, max_messages: usize, max_wait: Duration, ) -> Result<Vec<TypedMessage<S>>, PulsarError>

Batched receive. Mirrors Java Consumer#batchReceive. Decodes every payload with the schema; the first decode error short-circuits the call.

Source

pub async fn receive_batch_with_bytes_cap( &self, max_messages: usize, max_bytes: usize, max_wait: Duration, ) -> Result<Vec<TypedMessage<S>>, PulsarError>

Batched receive with a bytes cap. See Self::receive_batch and the runtime’s Consumer::receive_batch_with_bytes_cap for BatchReceivePolicy parity.

Source

pub async fn ack_with_properties( &self, message_id: MessageId, properties: Vec<(String, i64)>, ) -> Result<(), PulsarError>

Ack with caller-supplied properties. Mirrors Java Consumer#acknowledgeAsync(MessageId, Map<String, Long>).

Source

pub async fn ack_batch_with_txn( &self, message_ids: Vec<MessageId>, txn_id: TxnId, ) -> Result<(), PulsarError>

Batched ack inside a transaction. Mirrors Java Consumer#acknowledgeAsync(List<MessageId>, Transaction).

Source

pub async fn ack_cumulative_with_properties( &self, message_id: MessageId, properties: Vec<(String, i64)>, ) -> Result<(), PulsarError>

Cumulative ack with caller-supplied properties. Mirrors Java Consumer#acknowledgeCumulativeAsync(MessageId, Map<String, Long>).

Source

pub fn drain_dead_letter(&self) -> Vec<IncomingMessage>

Drain every DLQ-flagged message (raw, un-decoded so schema mismatches don’t lose the payload). See the runtime’s Consumer::drain_dead_letter.

Source

pub async fn republish_dead_letters( &self, dlq_producer: &Producer, ) -> Result<usize, PulsarError>

Drain the DLQ pending list and republish every entry via dlq_producer. See the runtime’s Consumer::republish_dead_letters. Returns the number republished.

With the opentelemetry feature on, the republish span context is re-injected onto every dead-letter copy (overwriting any inbound traceparent / tracestate) so the republish is traced under the caller’s current span; the original trace stays reachable via the REAL_TOPIC / ORIGINAL_MESSAGE_ID correlation stamps (ADR-0053 §D2).

Source

pub async fn reconsume_later( &self, retry_producer: &Producer, msg: IncomingMessage, delay: Duration, ) -> Result<(), PulsarError>

Republish msg via retry_producer with a delay, then ack the original. Mirrors Java Consumer#reconsumeLater(Message, long, TimeUnit). Takes the raw IncomingMessage (use TypedMessage::raw) so the original payload is preserved verbatim through the retry topic.

With the opentelemetry feature on, the retrying consumer’s current span context is re-injected onto the retry-letter copy, replacing the inbound traceparent / tracestate (ADR-0053 §D2).

Source

pub async fn reconsume_later_with_properties( &self, retry_producer: &Producer, msg: IncomingMessage, custom_properties: Vec<(String, String)>, delay: Duration, ) -> Result<(), PulsarError>

Same as Self::reconsume_later but stamps custom properties on the republished message. Mirrors Java’s properties-aware reconsumeLater overload.

With the opentelemetry feature on, the current span context is re-injected into custom_properties before the runtime merges them (override on key collision), so the retry-letter copy carries the retrying consumer’s trace rather than the inbound one (ADR-0053 §D2). An explicit traceparent / tracestate in custom_properties is overwritten by the injected value.

Trait Implementations§

Source§

impl<S: Schema, C: ConsumerApi + Debug> Debug for TypedConsumer<S, C>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S, C> Freeze for TypedConsumer<S, C>
where C: Freeze, Arc<S>: Freeze,

§

impl<S, C> RefUnwindSafe for TypedConsumer<S, C>

§

impl<S, C> Send for TypedConsumer<S, C>
where Arc<S>: Send,

§

impl<S, C> Sync for TypedConsumer<S, C>
where Arc<S>: Sync,

§

impl<S, C> Unpin for TypedConsumer<S, C>
where C: Unpin, Arc<S>: Unpin,

§

impl<S, C> UnsafeUnpin for TypedConsumer<S, C>
where C: UnsafeUnpin, Arc<S>: UnsafeUnpin,

§

impl<S, C> UnwindSafe for TypedConsumer<S, C>
where C: UnwindSafe, Arc<S>: 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