Class AbstractConsumerSeekAware

java.lang.Object
org.springframework.kafka.listener.AbstractConsumerSeekAware
All Implemented Interfaces:
ConsumerSeekAware

public abstract class AbstractConsumerSeekAware extends Object implements ConsumerSeekAware
Manages the ConsumerSeekAware.ConsumerSeekCallback s for the listener. If the listener subclasses this class, it can easily seek arbitrary topics/partitions without having to keep track of the callbacks itself.
Since:
2.3
Author:
Gary Russell
  • Constructor Details

    • AbstractConsumerSeekAware

      public AbstractConsumerSeekAware()
  • Method Details

    • registerSeekCallback

      public void registerSeekCallback(ConsumerSeekAware.ConsumerSeekCallback callback)
      Description copied from interface: ConsumerSeekAware
      Register the callback to use when seeking at some arbitrary time. When used with a ConcurrentMessageListenerContainer or the same listener instance in multiple containers listeners should store the callback in a ThreadLocal or a map keyed by the thread.
      Specified by:
      registerSeekCallback in interface ConsumerSeekAware
      Parameters:
      callback - the callback.
    • onPartitionsAssigned

      public void onPartitionsAssigned(Map<org.apache.kafka.common.TopicPartition,Long> assignments, ConsumerSeekAware.ConsumerSeekCallback callback)
      Description copied from interface: ConsumerSeekAware
      When using group management, called when partition assignments change.
      Specified by:
      onPartitionsAssigned in interface ConsumerSeekAware
      Parameters:
      assignments - the new assignments and their current offsets.
      callback - the callback to perform an initial seek after assignment.
    • onPartitionsRevoked

      public void onPartitionsRevoked(Collection<org.apache.kafka.common.TopicPartition> partitions)
      Description copied from interface: ConsumerSeekAware
      When using group management, called when partition assignments are revoked. Listeners should discard any callback saved from ConsumerSeekAware.registerSeekCallback(ConsumerSeekCallback) on this thread.
      Specified by:
      onPartitionsRevoked in interface ConsumerSeekAware
      Parameters:
      partitions - the partitions that have been revoked.
    • unregisterSeekCallback

      public void unregisterSeekCallback()
      Description copied from interface: ConsumerSeekAware
      Called when the listener consumer terminates allowing implementations to clean up state, such as thread locals.
      Specified by:
      unregisterSeekCallback in interface ConsumerSeekAware
    • getSeekCallbackFor

      @Nullable protected ConsumerSeekAware.ConsumerSeekCallback getSeekCallbackFor(org.apache.kafka.common.TopicPartition topicPartition)
      Return the callback for the specified topic/partition.
      Parameters:
      topicPartition - the topic/partition.
      Returns:
      the callback (or null if there is no assignment).
    • getSeekCallbacks

      protected Map<org.apache.kafka.common.TopicPartition,ConsumerSeekAware.ConsumerSeekCallback> getSeekCallbacks()
      The map of callbacks for all currently assigned partitions.
      Returns:
      the map.
    • getCallbacksAndTopics

      protected Map<ConsumerSeekAware.ConsumerSeekCallback,List<org.apache.kafka.common.TopicPartition>> getCallbacksAndTopics()
      Return the currently registered callbacks and their associated TopicPartition(s).
      Returns:
      the map of callbacks and partitions.
      Since:
      2.6
    • seekToBeginning

      public void seekToBeginning()
      Seek all assigned partitions to the beginning.
      Since:
      2.6
    • seekToEnd

      public void seekToEnd()
      Seek all assigned partitions to the end.
      Since:
      2.6
    • seekToTimestamp

      public void seekToTimestamp(long time)
      Seek all assigned partitions to the offset represented by the timestamp.
      Parameters:
      time - the time to seek to.
      Since:
      2.6