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:
acksettles 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
impl KafkaMessage
Sourcepub fn timestamp_millis(&self) -> Option<i64>
pub fn timestamp_millis(&self) -> Option<i64>
The record’s timestamp in milliseconds since the epoch, when the broker provided one.
Sourcepub fn key(&self) -> Option<&[u8]>
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
impl BuildContext<KafkaMessage> for KafkaContext
Source§fn build(msg: &KafkaMessage) -> Self
fn build(msg: &KafkaMessage) -> Self
msg.Source§impl Debug for KafkaMessage
impl Debug for KafkaMessage
Source§impl IncomingMessage for KafkaMessage
impl IncomingMessage for KafkaMessage
Source§async fn ack(self) -> Result<(), AckError>
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>
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]>
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 supports_nack_after(&self) -> bool
fn supports_nack_after(&self) -> bool
nack_after natively. Read moreSource§impl Partitioned for KafkaMessage
impl Partitioned for KafkaMessage
Source§fn partition_key(&self) -> Option<&[u8]>
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.