Class ConsumerRecord<K,V>

java.lang.Object
org.apache.kafka.clients.consumer.ConsumerRecord<K,V>

public class ConsumerRecord<K,V> extends Object
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.
  • Field Summary Link icon

    Fields
    Modifier and Type
    Field
    Description
    static final long
     
    static final int
     
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
    ConsumerRecord(String topic, int partition, long offset, long timestamp, org.apache.kafka.common.record.TimestampType timestampType, int serializedKeySize, int serializedValueSize, K key, V value, Headers headers, Optional<Integer> leaderEpoch)
    Creates a record to be received from a specified topic and partition.
    ConsumerRecord(String topic, int partition, long offset, long timestamp, org.apache.kafka.common.record.TimestampType timestampType, int serializedKeySize, int serializedValueSize, K key, V value, Headers headers, Optional<Integer> leaderEpoch, Optional<Short> deliveryCount)
    Creates a record to be received from a specified topic and partition.
    ConsumerRecord(String topic, int partition, long offset, K key, V value)
    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).
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    Get the delivery count for the record if available.
    The headers (never null)
    key()
    The key (or null if no key is specified)
    Get the leader epoch for the record if available
    long
    The position of this record in the corresponding Kafka partition.
    int
    The partition from which this record is received
    int
    The size of the serialized, uncompressed key in bytes.
    int
    The size of the serialized, uncompressed value in bytes.
    long
    The timestamp of this record, in milliseconds elapsed since unix epoch.
    org.apache.kafka.common.record.TimestampType
    The timestamp type of this record
    The topic this record is received from (never null)
     
    The value

    Methods inherited from class java.lang.Object Link icon

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details Link icon

  • Constructor Details Link icon

    • ConsumerRecord Link icon

      public ConsumerRecord(String topic, int partition, long offset, K key, V value)
      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).
      Parameters:
      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 (null is allowed)
      value - The record contents
    • ConsumerRecord Link icon

      public ConsumerRecord(String topic, int partition, long offset, long timestamp, org.apache.kafka.common.record.TimestampType timestampType, int serializedKeySize, int serializedValueSize, K key, V value, Headers headers, Optional<Integer> leaderEpoch)
      Creates a record to be received from a specified topic and partition.
      Parameters:
      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
      timestamp - The timestamp of the record.
      timestampType - The timestamp type
      serializedKeySize - The length of the serialized key
      serializedValueSize - The length of the serialized value
      key - The key of the record, if one exists (null is allowed)
      value - The record contents
      headers - The headers of the record
      leaderEpoch - Optional leader epoch of the record (may be empty for legacy record formats)
    • ConsumerRecord Link icon

      public ConsumerRecord(String topic, int partition, long offset, long timestamp, org.apache.kafka.common.record.TimestampType timestampType, int serializedKeySize, int serializedValueSize, K key, V value, Headers headers, Optional<Integer> leaderEpoch, Optional<Short> deliveryCount)
      Creates a record to be received from a specified topic and partition.
      Parameters:
      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
      timestamp - The timestamp of the record.
      timestampType - The timestamp type
      serializedKeySize - The length of the serialized key
      serializedValueSize - The length of the serialized value
      key - The key of the record, if one exists (null is allowed)
      value - The record contents
      headers - The headers of the record
      leaderEpoch - Optional leader epoch of the record (may be empty for legacy record formats)
      deliveryCount - Optional delivery count of the record (may be empty when deliveries not counted)
  • Method Details Link icon

    • topic Link icon

      public String topic()
      The topic this record is received from (never null)
    • partition Link icon

      public int partition()
      The partition from which this record is received
    • headers Link icon

      public Headers headers()
      The headers (never null)
    • key Link icon

      public K key()
      The key (or null if no key is specified)
    • value Link icon

      public V value()
      The value
    • offset Link icon

      public long offset()
      The position of this record in the corresponding Kafka partition.
    • timestamp Link icon

      public long timestamp()
      The timestamp of this record, in milliseconds elapsed since unix epoch.
    • timestampType Link icon

      public org.apache.kafka.common.record.TimestampType timestampType()
      The timestamp type of this record
    • serializedKeySize Link icon

      public int serializedKeySize()
      The size of the serialized, uncompressed key in bytes. If key is null, the returned size is -1.
    • serializedValueSize Link icon

      public int serializedValueSize()
      The size of the serialized, uncompressed value in bytes. If value is null, the returned size is -1.
    • leaderEpoch Link icon

      public Optional<Integer> leaderEpoch()
      Get the leader epoch for the record if available
      Returns:
      the leader epoch or empty for legacy record formats
    • deliveryCount Link icon

      public Optional<Short> deliveryCount()
      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
    • toString Link icon

      public String toString()
      Overrides:
      toString in class Object