Skip to main content

ConsumerRecord

Struct ConsumerRecord 

Source
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>

Source

pub const NO_TIMESTAMP: i64 = -1

Sentinel value indicating no timestamp is associated with a record.

Source

pub const NULL_SIZE: i32 = -1

Sentinel value used for serialized_key_size / serialized_value_size when the key/value is None.

Source

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 from
  • partition - The partition of the topic this record is received from
  • offset - The offset of this record in the corresponding Kafka partition
  • key - The key of the record, if one exists (None is allowed)
  • value - The record contents
§Returns

The new ConsumerRecord.

Source

pub fn with_options(options: ConsumerRecordOptions<K, V>) -> Self

Creates a record to be received from a specified topic and partition.

§Arguments
  • options - The topic, partition, offset, timestamp, timestamp type, serialized key and value sizes, key, value, headers, leader epoch and delivery count of the record
§Returns

The new ConsumerRecord.

Source

pub fn topic(&self) -> &str

Returns the topic this record is received from.

Source

pub fn partition(&self) -> i32

Returns the partition from which this record is received.

Source

pub fn offset(&self) -> i64

Returns the position of this record in the corresponding Kafka partition.

Source

pub fn timestamp(&self) -> i64

Returns the timestamp of this record, in milliseconds elapsed since unix epoch.

Source

pub fn timestamp_type(&self) -> TimestampType

Returns the timestamp type of this record.

Source

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.

Source

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.

Source

pub fn key(&self) -> Option<&K>

Returns the key (or None if no key is specified).

Source

pub fn value(&self) -> Option<&V>

Returns the value.

Source

pub fn headers(&self) -> &RecordHeaders

Returns the headers.

Source

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

Source

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

Trait Implementations§

Source§

impl<K: Clone, V: Clone> Clone for ConsumerRecord<K, V>

Source§

fn clone(&self) -> ConsumerRecord<K, V>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K, V> Debug for ConsumerRecord<K, V>
where K: Debug, V: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, V> Display for ConsumerRecord<K, V>
where K: Debug, V: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K, V> Freeze for ConsumerRecord<K, V>
where K: Freeze, V: Freeze,

§

impl<K, V> RefUnwindSafe for ConsumerRecord<K, V>

§

impl<K, V> Send for ConsumerRecord<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for ConsumerRecord<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for ConsumerRecord<K, V>
where K: Unpin, V: Unpin,

§

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V