Class 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

      Fields 
      Modifier and Type Field Description
      static long NO_TIMESTAMP  
      static int NULL_CHECKSUM
      Deprecated.
      checksums are no longer exposed by this class, this constant will be removed in Apache Kafka 4.0 (deprecated since 3.0).
      static int NULL_SIZE  
    • Constructor Summary

      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, String producer)
      MapR specific constructor.
      ConsumerRecord​(String topic, int partition, long offset, long timestamp, org.apache.kafka.common.record.TimestampType timestampType, long checksum, int serializedKeySize, int serializedValueSize, K key, V value)
      Deprecated.
      use one of the constructors without a `checksum` parameter.
      ConsumerRecord​(String topic, int partition, long offset, long timestamp, org.apache.kafka.common.record.TimestampType timestampType, Long checksum, int serializedKeySize, int serializedValueSize, K key, V value, Headers headers)
      Deprecated.
      use one of the constructors without a `checksum` parameter.
      ConsumerRecord​(String topic, int partition, long offset, long timestamp, org.apache.kafka.common.record.TimestampType timestampType, Long checksum, int serializedKeySize, int serializedValueSize, K key, V value, Headers headers, Optional<Integer> leaderEpoch)
      Deprecated.
      use one of the constructors without a `checksum` parameter.
      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).
    • Field Detail

      • NULL_CHECKSUM

        @Deprecated
        public static final int NULL_CHECKSUM
        Deprecated.
        checksums are no longer exposed by this class, this constant will be removed in Apache Kafka 4.0 (deprecated since 3.0).
        See Also:
        Constant Field Values
    • Constructor Detail

      • ConsumerRecord

        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

        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

        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,
                              String producer)
        MapR specific constructor. Copy of ConsumerRecord#ConsumerRecord( String, int, long, long, TimestampType, int, int, K, V, Headers, Optional), but with MapR specific field for producer. 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)
        producer - Producer of this record
      • ConsumerRecord

        @Deprecated
        public ConsumerRecord​(String topic,
                              int partition,
                              long offset,
                              long timestamp,
                              org.apache.kafka.common.record.TimestampType timestampType,
                              long checksum,
                              int serializedKeySize,
                              int serializedValueSize,
                              K key,
                              V value)
        Deprecated.
        use one of the constructors without a `checksum` parameter. This constructor will be removed in Apache Kafka 4.0 (deprecated since 3.0).
        Creates a record to be received from a specified topic and partition (provided for compatibility with Kafka 0.10 before the message format supported headers).
        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
      • ConsumerRecord

        @Deprecated
        public ConsumerRecord​(String topic,
                              int partition,
                              long offset,
                              long timestamp,
                              org.apache.kafka.common.record.TimestampType timestampType,
                              Long checksum,
                              int serializedKeySize,
                              int serializedValueSize,
                              K key,
                              V value,
                              Headers headers)
        Deprecated.
        use one of the constructors without a `checksum` parameter. This constructor will be removed in Apache Kafka 4.0 (deprecated since 3.0).
        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.
      • ConsumerRecord

        @Deprecated
        public ConsumerRecord​(String topic,
                              int partition,
                              long offset,
                              long timestamp,
                              org.apache.kafka.common.record.TimestampType timestampType,
                              Long checksum,
                              int serializedKeySize,
                              int serializedValueSize,
                              K key,
                              V value,
                              Headers headers,
                              Optional<Integer> leaderEpoch)
        Deprecated.
        use one of the constructors without a `checksum` parameter. This constructor will be removed in Apache Kafka 4.0 (deprecated since 3.0).
        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)
    • Method Detail

      • topic

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

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

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

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

        public V value()
        The value
      • offset

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

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

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

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

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

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

        public String producer()
        MapR specific method, always returns null in Apache Kafka. Get the producer of this record if available
        Returns:
        the leader epoch or empty for legacy record formats