Class AbstractConsumerSeekAware
java.lang.Object
org.springframework.kafka.listener.AbstractConsumerSeekAware
- All Implemented Interfaces:
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.kafka.listener.ConsumerSeekAware
ConsumerSeekAware.ConsumerSeekCallback -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Map<ConsumerSeekAware.ConsumerSeekCallback,List<org.apache.kafka.common.TopicPartition>> Return the currently registered callbacks and their associatedTopicPartition(s).protected ConsumerSeekAware.ConsumerSeekCallbackgetSeekCallbackFor(org.apache.kafka.common.TopicPartition topicPartition) Return the callback for the specified topic/partition.protected Map<org.apache.kafka.common.TopicPartition,ConsumerSeekAware.ConsumerSeekCallback> The map of callbacks for all currently assigned partitions.voidonPartitionsAssigned(Map<org.apache.kafka.common.TopicPartition, Long> assignments, ConsumerSeekAware.ConsumerSeekCallback callback) When using group management, called when partition assignments change.voidonPartitionsRevoked(Collection<org.apache.kafka.common.TopicPartition> partitions) When using group management, called when partition assignments are revoked.voidRegister the callback to use when seeking at some arbitrary time.voidSeek all assigned partitions to the beginning.voidSeek all assigned partitions to the end.voidseekToTimestamp(long time) Seek all assigned partitions to the offset represented by the timestamp.voidCalled when the listener consumer terminates allowing implementations to clean up state, such as thread locals.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.kafka.listener.ConsumerSeekAware
onFirstPoll, onIdleContainer
-
Constructor Details
-
AbstractConsumerSeekAware
public AbstractConsumerSeekAware()
-
-
Method Details
-
registerSeekCallback
Description copied from interface:ConsumerSeekAwareRegister the callback to use when seeking at some arbitrary time. When used with aConcurrentMessageListenerContaineror the same listener instance in multiple containers listeners should store the callback in aThreadLocal.- Specified by:
registerSeekCallbackin interfaceConsumerSeekAware- Parameters:
callback- the callback.
-
onPartitionsAssigned
public void onPartitionsAssigned(Map<org.apache.kafka.common.TopicPartition, Long> assignments, ConsumerSeekAware.ConsumerSeekCallback callback) Description copied from interface:ConsumerSeekAwareWhen using group management, called when partition assignments change.- Specified by:
onPartitionsAssignedin interfaceConsumerSeekAware- Parameters:
assignments- the new assignments and their current offsets.callback- the callback to perform an initial seek after assignment.
-
onPartitionsRevoked
Description copied from interface:ConsumerSeekAwareWhen using group management, called when partition assignments are revoked. Listeners should discard any callback saved fromConsumerSeekAware.registerSeekCallback(ConsumerSeekCallback)on this thread.- Specified by:
onPartitionsRevokedin interfaceConsumerSeekAware- Parameters:
partitions- the partitions that have been revoked.
-
unregisterSeekCallback
public void unregisterSeekCallback()Description copied from interface:ConsumerSeekAwareCalled when the listener consumer terminates allowing implementations to clean up state, such as thread locals.- Specified by:
unregisterSeekCallbackin interfaceConsumerSeekAware
-
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 associatedTopicPartition(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
-