Class AbstractConsumerSeekAware

  • All Implemented Interfaces:
    ConsumerSeekAware

    public abstract class AbstractConsumerSeekAware
    extends java.lang.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 Detail

      • AbstractConsumerSeekAware

        public AbstractConsumerSeekAware()
    • Method Detail

      • 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.
        Specified by:
        registerSeekCallback in interface ConsumerSeekAware
        Parameters:
        callback - the callback.
      • onPartitionsAssigned

        public void onPartitionsAssigned​(java.util.Map<org.apache.kafka.common.TopicPartition,​java.lang.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.
      • 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 java.util.Map<org.apache.kafka.common.TopicPartition,​ConsumerSeekAware.ConsumerSeekCallback> getSeekCallbacks()
        The map of callbacks for all currently assigned partitions.
        Returns:
        the map.
      • getCallbacksAndTopics

        protected java.util.Map<ConsumerSeekAware.ConsumerSeekCallback,​java.util.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