Class RecordMetadata

java.lang.Object
org.apache.kafka.clients.producer.RecordMetadata

public final class RecordMetadata
extends Object
The metadata for a record that has been acknowledged by the server
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int UNKNOWN_PARTITION
    Partition value for record without partition assigned
  • Constructor Summary

    Constructors
    Constructor Description
    RecordMetadata​(TopicPartition topicPartition, long baseOffset, int batchIndex, long timestamp, int serializedKeySize, int serializedValueSize)
    Creates a new instance with the provided parameters.
    RecordMetadata​(TopicPartition topicPartition, long baseOffset, long batchIndex, long timestamp, Long checksum, int serializedKeySize, int serializedValueSize)
    Deprecated.
    use constructor without `checksum` parameter.
  • Method Summary

    Modifier and Type Method Description
    boolean hasOffset()
    Indicates whether the record metadata includes the offset.
    boolean hasTimestamp()
    Indicates whether the record metadata includes the timestamp.
    long offset()
    The offset of the record in the topic/partition.
    int partition()
    The partition the record was sent to
    int serializedKeySize()
    The size of the serialized, uncompressed key in bytes.
    int serializedValueSize()
    The size of the serialized, uncompressed value in bytes.
    long timestamp()
    The timestamp of the record in the topic/partition.
    String topic()
    The topic the record was appended to
    String toString()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • UNKNOWN_PARTITION

      public static final int UNKNOWN_PARTITION
      Partition value for record without partition assigned
      See Also:
      Constant Field Values
  • Constructor Details

    • RecordMetadata

      public RecordMetadata​(TopicPartition topicPartition, long baseOffset, int batchIndex, long timestamp, int serializedKeySize, int serializedValueSize)
      Creates a new instance with the provided parameters.
    • RecordMetadata

      @Deprecated public RecordMetadata​(TopicPartition topicPartition, long baseOffset, long batchIndex, long timestamp, Long checksum, int serializedKeySize, int serializedValueSize)
      Deprecated.
      use constructor without `checksum` parameter. This constructor will be removed in Apache Kafka 4.0 (deprecated since 3.0).
      Creates a new instance with the provided parameters.
  • Method Details

    • hasOffset

      public boolean hasOffset()
      Indicates whether the record metadata includes the offset.
      Returns:
      true if the offset is included in the metadata, false otherwise.
    • offset

      public long offset()
      The offset of the record in the topic/partition.
      Returns:
      the offset of the record, or -1 if {hasOffset()} returns false.
    • hasTimestamp

      public boolean hasTimestamp()
      Indicates whether the record metadata includes the timestamp.
      Returns:
      true if a valid timestamp exists, false otherwise.
    • timestamp

      public long timestamp()
      The timestamp of the record in the topic/partition.
      Returns:
      the timestamp of the record, or -1 if the {hasTimestamp()} returns false.
    • 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.
    • topic

      public String topic()
      The topic the record was appended to
    • partition

      public int partition()
      The partition the record was sent to
    • toString

      public String toString()
      Overrides:
      toString in class Object