Skip to main content

KafkaMessage

Struct KafkaMessage 

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

One Kafka delivery: an owned snapshot of the record plus its settlement handle.

Settlement mapping depends on the Commit mode of the subscription:

Under Commit::Auto (the default) librdkafka owns the committed position - it is stored the moment a message is handed to the application - so ack and both nack forms are advisory no-ops; in particular nack(true) does NOT cause a redelivery.

Under Commit::Tracked:

  • ack settles the offset and advances the stored position across everything settled below it.
  • nack(false) drops the message: the offset settles so the position can move past it (Kafka has no per-message dead-letter path; a dead-letter topic is a planned descriptor option).
  • nack(true) leaves the offset unsettled: the committed position stays below it, so Kafka redelivers from there when the partition is next re-fetched (a rebalance or a restart). Until then the unsettled offset also blocks the position, keeping every later ack uncommitted - precise, but worth knowing when a handler nacks in a loop.

Wire headers map name for name; a null-valued Kafka header arrives with an empty value (presence preserved).

Implementations§

Source§

impl KafkaMessage

Source

pub fn topic(&self) -> &str

The topic this record was consumed from.

Source

pub fn partition(&self) -> i32

The partition this record was consumed from.

Source

pub fn offset(&self) -> i64

The record’s offset within its partition.

Source

pub fn timestamp_millis(&self) -> Option<i64>

The record’s timestamp in milliseconds since the epoch, when the broker provided one.

Source

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

The record key, surfaced from Kafka’s native key (see PARTITION_KEY_HEADER).

Trait Implementations§

Source§

impl BuildContext<KafkaMessage> for KafkaContext

Source§

fn build(msg: &KafkaMessage) -> Self

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

impl Debug for KafkaMessage

Source§

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

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

impl IncomingMessage for KafkaMessage

Source§

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

Marks the offset processed (see the type-level settlement mapping).

§Errors

Returns AckError::Broker when the offset store rejects the new position, for example because enable.auto.offset.store was overridden back to true on a Commit::Tracked subscription.

§Cancel safety

Cancel safe: the watermark update is synchronous, so the future either completed or did nothing.

Source§

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

Settles negatively. With a Retry policy configured on the subscription, requeue = true runs it (republish to the retry topic, seek back, or drop) and requeue = false runs the drop path (dead-letter when configured, then settle). Without a policy, requeue = false settles the offset and requeue = true leaves it unsettled for Kafka’s native re-consumption - which under Commit::Auto makes both forms advisory no-ops (see the type-level settlement mapping).

§Errors

Returns AckError::Broker when a retry/dead-letter republish or seek fails, and under the same conditions as ack.

§Cancel safety

Without a policy: cancel safe (the watermark update is synchronous). With a policy: not cancel safe - dropping the future may leave the retry or dead-letter copy published with the original unsettled (a duplicate, never a loss).

Source§

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

The keyed-lane key, so keyed worker lanes see it without a Partitioned bound: the source partition (the default), or the record key under LaneKey::RecordKey.

Source§

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

Returns the raw payload of the message.
Source§

fn headers(&self) -> &Headers

Returns the headers attached to the message.
Source§

fn supports_nack_after(&self) -> bool

Reports whether this transport can honor nack_after natively. Read more
Source§

fn nack_after( self, delay: Duration, ) -> impl Future<Output = Result<(), AckError>> + Send
where Self: Sized,

Negatively acknowledges the message, asking the broker to redeliver it no sooner than delay from now. Read more
Source§

impl Partitioned for KafkaMessage

Source§

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

The keyed-lane key (see IncomingMessage::partition_key on this type): the source partition (the default), or the record key under LaneKey::RecordKey.

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