Class OffsetAndMetadata

  • All Implemented Interfaces:
    java.io.Serializable

    public class OffsetAndMetadata
    extends java.lang.Object
    implements java.io.Serializable
    The Kafka offset commit API allows users to provide additional metadata (in the form of a string) when an offset is committed. This can be useful (for example) to store information about which node made the commit, what time the commit was made, etc.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      OffsetAndMetadata​(long offset)
      Construct a new OffsetAndMetadata object for committing through KafkaConsumer.
      OffsetAndMetadata​(long offset, java.lang.String metadata)
      Construct a new OffsetAndMetadata object for committing through KafkaConsumer.
      OffsetAndMetadata​(long offset, java.util.Optional<java.lang.Integer> leaderEpoch, java.lang.String metadata)
      Construct a new OffsetAndMetadata object for committing through KafkaConsumer.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      int hashCode()  
      java.util.Optional<java.lang.Integer> leaderEpoch()
      Get the leader epoch of the previously consumed record (if one is known).
      java.lang.String metadata()  
      long offset()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • OffsetAndMetadata

        public OffsetAndMetadata​(long offset,
                                 java.util.Optional<java.lang.Integer> leaderEpoch,
                                 java.lang.String metadata)
        Construct a new OffsetAndMetadata object for committing through KafkaConsumer.
        Parameters:
        offset - The offset to be committed
        leaderEpoch - Optional leader epoch of the last consumed record
        metadata - Non-null metadata
      • OffsetAndMetadata

        public OffsetAndMetadata​(long offset,
                                 java.lang.String metadata)
        Construct a new OffsetAndMetadata object for committing through KafkaConsumer.
        Parameters:
        offset - The offset to be committed
        metadata - Non-null metadata
      • OffsetAndMetadata

        public OffsetAndMetadata​(long offset)
        Construct a new OffsetAndMetadata object for committing through KafkaConsumer. The metadata associated with the commit will be empty.
        Parameters:
        offset - The offset to be committed
    • Method Detail

      • offset

        public long offset()
      • metadata

        public java.lang.String metadata()
      • leaderEpoch

        public java.util.Optional<java.lang.Integer> leaderEpoch()
        Get the leader epoch of the previously consumed record (if one is known). Log truncation is detected if there exists a leader epoch which is larger than this epoch and begins at an offset earlier than the committed offset.
        Returns:
        the leader epoch or empty if not known
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object