pub struct ConsumerRecord<K, V> { /* private fields */ }Expand description
A key/value pair received from Kafka.
Corresponds to Java’s org.apache.kafka.clients.consumer.ConsumerRecord<K,V>.
Per consumer-threading.md §27, the topic is an Arc<str> that is
shared cheaply across all records from the same topic-partition (via
SubscriptionState), and the headers are owned for this milestone
(matching Java’s allocation behavior).
§Thread safety
Mirrors Java’s behavior: this struct is not designed for concurrent
mutation; Headers are mutable. Concurrent reads are safe by Rust’s
borrow rules.
§Equality
PartialEq / Eq are derived (gated on K: PartialEq, V: PartialEq /
K: Eq, V: Eq) so that tests can compare two record batches for
structural equality. This mirrors Java’s behavior where
ConsumerRecord equality is value-based; the Java class itself does
not override equals, but its fields are all value types, so two
records with identical fields compare equal via Objects.equals.
The cost is paid only by callers that opt in to PartialEq types
(e.g. tests using i32 keys); users with non-PartialEq K/V
continue to work because the bounds are gated by the derive.
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.
Corresponds to Java’s RecordBatch.NO_TIMESTAMP referenced via
ConsumerRecord.NO_TIMESTAMP.
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.
Corresponds to Java’s ConsumerRecord.NULL_SIZE.
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 from a specified topic and partition.
Corresponds to Java’s ConsumerRecord(String, int, long, K, V)
(ConsumerRecord.java:83), whose parameters
{topic, partition, offset, key, value} are the intersection across
the three constructors — so it owns the plain name (CLAUDE.md §2).
The timestamp is set to ConsumerRecord::NO_TIMESTAMP, the timestamp type to
TimestampType::NoTimestampType, the serialized sizes to
ConsumerRecord::NULL_SIZE, headers to an empty RecordHeaders, and both
leader_epoch and delivery_count to None.
Sourcepub fn with_options(options: ConsumerRecordOptions<K, V>) -> Self
pub fn with_options(options: ConsumerRecordOptions<K, V>) -> Self
Creates a record with full metadata.
Corresponds to Java’s widest constructor
(ConsumerRecord.java:138), which takes deliveryCount alongside
every other field. Its twelve parameters exceed CLAUDE.md §2’s
three-parameter cap on derived overload names, so
ConsumerRecordOptions is this method’s only parameter and carries
all of them.
Java’s intermediate 11-arg constructor (ConsumerRecord.java:107) is
not a separate Rust method: its body is literally this one with
deliveryCount = Optional.empty(), and under CLAUDE.md §2 both derive
the same name with_options once the surplus parameters move into
ConsumerRecordOptions. Callers get the 11-arg form by leaving
ConsumerRecordOptions::delivery_count at None.
options- every parameter of Java’s widest constructor
Sourcepub fn timestamp(&self) -> i64
pub fn timestamp(&self) -> i64
The timestamp of this record, in milliseconds elapsed since unix epoch.
Sourcepub fn timestamp_type(&self) -> TimestampType
pub fn timestamp_type(&self) -> TimestampType
The timestamp type of this record.
Sourcepub fn serialized_key_size(&self) -> i32
pub fn serialized_key_size(&self) -> i32
The size of the serialized, uncompressed key in bytes. Returns
ConsumerRecord::NULL_SIZE (-1) if the key is None.
Sourcepub fn serialized_value_size(&self) -> i32
pub fn serialized_value_size(&self) -> i32
The size of the serialized, uncompressed value in bytes. Returns
ConsumerRecord::NULL_SIZE (-1) if the value is None.
Sourcepub fn headers(&self) -> &RecordHeaders
pub fn headers(&self) -> &RecordHeaders
The headers (never null).
Sourcepub fn leader_epoch(&self) -> Option<i32>
pub fn leader_epoch(&self) -> Option<i32>
Get the leader epoch for the record if available.
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.
Trait Implementations§
Source§impl<K, V> Debug for ConsumerRecord<K, V>
impl<K, V> Debug for ConsumerRecord<K, V>
Source§impl<K, V> Display for ConsumerRecord<K, V>
impl<K, V> Display for ConsumerRecord<K, V>
impl<K: Eq, V: Eq> Eq for ConsumerRecord<K, V>
impl<K, V> StructuralPartialEq for ConsumerRecord<K, V>
Auto Trait Implementations§
impl<K, V> Freeze for ConsumerRecord<K, V>
impl<K, V> RefUnwindSafe for ConsumerRecord<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for ConsumerRecord<K, V>
impl<K, V> Sync for ConsumerRecord<K, V>
impl<K, V> Unpin for ConsumerRecord<K, V>
impl<K, V> UnsafeUnpin for ConsumerRecord<K, V>where
K: UnsafeUnpin,
V: UnsafeUnpin,
impl<K, V> UnwindSafe for ConsumerRecord<K, V>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.