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: drops the offset (requeue = false) or leaves it unsettled for Kafka’s native re-consumption (requeue = true). Only meaningful under Commit::Tracked; under Commit::Auto both forms are advisory no-ops (see the type-level settlement mapping).

§Errors

Returns AckError::Broker under the same conditions as ack.

§Cancel safety

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

Source§

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

The record key, so keyed worker lanes see it without a Partitioned bound.

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 record key Kafka partitioned this message by, or None for keyless records.

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