pub struct ConsumerRecord<K, V> { /* private fields */ }Expand description
A key/value pair to be received from Kafka. This also consists of a topic
name and a partition number from which the record is being received, an
offset that points to the record in a Kafka partition, and a timestamp as
marked by the corresponding ProducerRecord.
§Translation notes
Java’s record is not thread-safe because headers() hands out a mutable
collection; here it hands out a shared reference, so the borrow rules make
concurrent reads safe.
Implementations§
Source§impl<K, V> ConsumerRecord<K, V>
impl<K, V> ConsumerRecord<K, V>
Sourcepub const NO_TIMESTAMP: i64 = -1
pub const NO_TIMESTAMP: i64 = -1
Sentinel value indicating no timestamp is associated with a record.
Sourcepub const NULL_SIZE: i32 = -1
pub const NULL_SIZE: i32 = -1
Sentinel value used for serialized_key_size / serialized_value_size
when the key/value is None.
Sourcepub fn new(
topic: impl Into<Arc<str>>,
partition: i32,
offset: i64,
key: Option<K>,
value: Option<V>,
) -> Self
pub fn new( topic: impl Into<Arc<str>>, partition: i32, offset: i64, key: Option<K>, value: Option<V>, ) -> Self
Creates a record to be received from a specified topic and partition (provided for compatibility with Kafka 0.9 before the message format supported timestamps and before serialized metadata were exposed).
§Arguments
topic- The topic this record is received frompartition- The partition of the topic this record is received fromoffset- The offset of this record in the corresponding Kafka partitionkey- The key of the record, if one exists (Noneis allowed)value- The record contents
§Returns
The new ConsumerRecord.
Sourcepub fn with_options(options: ConsumerRecordOptions<K, V>) -> Self
pub fn with_options(options: ConsumerRecordOptions<K, V>) -> Self
Sourcepub fn offset(&self) -> i64
pub fn offset(&self) -> i64
Returns the position of this record in the corresponding Kafka partition.
Sourcepub fn timestamp(&self) -> i64
pub fn timestamp(&self) -> i64
Returns the timestamp of this record, in milliseconds elapsed since unix epoch.
Sourcepub fn timestamp_type(&self) -> TimestampType
pub fn timestamp_type(&self) -> TimestampType
Returns the timestamp type of this record.
Sourcepub fn serialized_key_size(&self) -> i32
pub fn serialized_key_size(&self) -> i32
Returns the size of the serialized, uncompressed key in bytes. If key is
None, the returned size is -1.
Sourcepub fn serialized_value_size(&self) -> i32
pub fn serialized_value_size(&self) -> i32
Returns the size of the serialized, uncompressed value in bytes. If value
is None, the returned size is -1.
Sourcepub fn headers(&self) -> &RecordHeaders
pub fn headers(&self) -> &RecordHeaders
Returns the headers.
Sourcepub fn leader_epoch(&self) -> Option<i32>
pub fn leader_epoch(&self) -> Option<i32>
Get the leader epoch for the record if available.
§Returns
the leader epoch or empty for legacy record formats
Sourcepub fn delivery_count(&self) -> Option<i16>
pub fn delivery_count(&self) -> Option<i16>
Get the delivery count for the record if available.
Deliveries are counted for records delivered by share groups.
§Returns
the delivery count or empty when deliveries not counted