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 nack(false) are advisory no-ops, and nack(true) reports AckError::Unsupported: nothing brings the record back.

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.
  • nack(true) hands the delivery back to its subscription, which delivers it again ahead of what it fetches next. Its offset stays unsettled meanwhile, so the committed position stays below it: were the process to stop first, Kafka redelivers the record from there to whoever reads the partition next. A rebalance or a seek that moves the partition before the delivery comes back drops it for the same reason. Until it settles, the unsettled offset also blocks the position, keeping every later ack uncommitted.

Under Commit::Transactional the settlements report to the exactly-once pipeline instead, and nack(true) keeps the open window from committing: it aborts, and its replay delivers the record again with the rest of the window.

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.

Read from the record on the ask rather than carried by the delivery: librdkafka answers it out of the fetch buffer this delivery holds open, and most deliveries are never asked.

Source

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

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

Trait Implementations§

Source§

impl BuildBatchContext<KafkaMessage> for KafkaBatchContext

Source§

fn build(first: &KafkaMessage) -> Self

Builds the context value by reading subscription-scoped fields out of the batch’s first delivery, or out of the batch itself where it lends its values as one slice.
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§

fn ack(self) -> impl Future<Output = Result<(), AckError>>

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

§Errors

Returns AckError::Broker when librdkafka refuses the stored position, which is a client-state failure rather than a network one - the partition is no longer this consumer’s, say. A descriptor passthrough that would take the offset store back is not one of those cases and never reaches here: librdkafka would accept the store and keep owning the position, so Commit::Tracked and Commit::Transactional refuse such a subscription at startup instead.

§Cancel safety

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

Source§

fn nack(self, requeue: bool) -> impl Future<Output = Result<(), AckError>>

Settles negatively. requeue = false drops the delivery: the offset settles so the committed position can move past it. requeue = true hands the delivery back to its subscription, which delivers it again; its offset stays unsettled until then. Under Commit::Transactional it aborts the open window, whose replay delivers it again. Under Commit::Auto requeue = false is an advisory no-op and requeue = true is unsupported (see the type-level settlement mapping).

Kafka counts no deliveries of its own, so a registration that caps its attempts with max_attempts(..) gets the framework’s count instead: the runtime republishes the delivery through the registration’s retry publisher so the count travels with it.

§Errors

Returns AckError::Unsupported for requeue = true under Commit::Auto, where the position was stored when the record was handed over, and 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 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) -> &HeaderMap

Returns the headers attached to the message.
Source§

fn redelivery_count(&self) -> Option<u64>

How many times the broker has delivered this message, counting this delivery. None where the transport counts nothing. Read more
Source§

fn decode_error(&self) -> Option<&CodecError>

The error the broker met while reading this delivery, or None when it read the delivery whole. Read more
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.

Source§

impl Positioned for KafkaMessage

Source§

fn position(&self) -> Self::Position

This delivery’s own coordinates: seeking to them redelivers exactly this record (and the ordered suffix behind it on the partition).

Source§

type Position = KafkaPosition

The position type, matching the subscription’s Seeker::Position.

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> ErasedDestructor for T
where T: 'static,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> PublishedThrough<DefaultSlot> for T

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

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