Class TopicPartitionOffset

java.lang.Object
org.springframework.kafka.support.TopicPartitionOffset

public class TopicPartitionOffset extends Object
A configuration container to represent a topic name, partition number and, optionally, an offset for it. The offset can be:
  • null - do nothing;
  • positive (including 0) - seek to EITHER the absolute offset within the partition or an offset relative to the current position for this consumer, depending on isRelativeToCurrent().
  • negative - seek to EITHER the offset relative to the current last offset within the partition: consumer.seekToEnd() + initialOffset OR the relative to the current offset for this consumer (if any), depending on isRelativeToCurrent().
Offsets are applied when the container is start()ed. This class is used when manually assigning partitions and for deferred seek operations.
Since:
2.3
Author:
Artem Bilan, Gary Russell, Soby Chacko
  • Constructor Details

    • TopicPartitionOffset

      public TopicPartitionOffset(String topic, int partition)
      Construct an instance with no initial offset management.
      Parameters:
      topic - the topic.
      partition - the partition.
    • TopicPartitionOffset

      public TopicPartitionOffset(@Nullable String topic, int partition, @Nullable Long offset)
      Construct an instance with the provided initial offset with isRelativeToCurrent() false.
      Parameters:
      topic - the topic.
      partition - the partition.
      offset - the offset.
      See Also:
    • TopicPartitionOffset

      public TopicPartitionOffset(@Nullable String topic, int partition, Function<Long,Long> offsetComputeFunction)
      Construct an instance with the provided function to compute the offset.
      Parameters:
      topic - the topic.
      partition - the partition.
      offsetComputeFunction - function to compute the offset.
      Since:
      3.2.0
    • TopicPartitionOffset

      public TopicPartitionOffset(@Nullable String topic, int partition, @Nullable Long offset, boolean relativeToCurrent)
      Construct an instance with the provided initial offset.
      Parameters:
      topic - the topic.
      partition - the partition.
      offset - the initial offset.
      relativeToCurrent - true for the initial offset to be relative to the current consumer position, false for a positive initial offset to be absolute and a negative offset relative to the current end of the partition.
    • TopicPartitionOffset

      public TopicPartitionOffset(String topic, int partition, TopicPartitionOffset.SeekPosition position)
      Construct an instance with the provided TopicPartitionOffset.SeekPosition.
      Parameters:
      topic - the topic.
      partition - the partition.
      position - TopicPartitionOffset.SeekPosition.
    • TopicPartitionOffset

      public TopicPartitionOffset(@Nullable String topic, int partition, @Nullable Long offset, @Nullable TopicPartitionOffset.SeekPosition position)
      Construct an instance with the provided TopicPartitionOffset.SeekPosition.
      Parameters:
      topic - the topic.
      partition - the partition.
      offset - the offset from the seek position (or timestamp for TopicPartitionOffset.SeekPosition.TIMESTAMP).
      position - TopicPartitionOffset.SeekPosition.
      Since:
      2.3
    • TopicPartitionOffset

      public TopicPartitionOffset(org.apache.kafka.common.TopicPartition topicPartition, @Nullable Long offset, @Nullable TopicPartitionOffset.SeekPosition position)
      Construct an instance with the provided TopicPartitionOffset.SeekPosition.
      Parameters:
      topicPartition - the topic/partition.
      offset - the offset from the seek position (or timestamp for TopicPartitionOffset.SeekPosition.TIMESTAMP).
      position - TopicPartitionOffset.SeekPosition.
      Since:
      2.3
  • Method Details

    • getTopicPartition

      public org.apache.kafka.common.TopicPartition getTopicPartition()
    • getPartition

      public int getPartition()
    • getTopic

      public String getTopic()
    • getOffset

      public @Nullable Long getOffset()
    • setOffset

      public void setOffset(Long offset)
      Set the offset.
      Parameters:
      offset - the offset.
      Since:
      2.5.5
    • isRelativeToCurrent

      public boolean isRelativeToCurrent()
    • setRelativeToCurrent

      public void setRelativeToCurrent(boolean relativeToCurrent)
      Set whether the offset is relative to the current position.
      Parameters:
      relativeToCurrent - true for relative to current.
      Since:
      2.5.5
    • getPosition

      public @Nullable TopicPartitionOffset.SeekPosition getPosition()
    • getOffsetComputeFunction

      public @Nullable Function<Long,Long> getOffsetComputeFunction()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object