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, Borahm Lee
-
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.ConsumerSeekCallback
getSeekCallbackFor
(org.apache.kafka.common.TopicPartition topicPartition) Deprecated, for removal: This API element is subject to removal in a future version.protected Map<org.apache.kafka.common.TopicPartition,
ConsumerSeekAware.ConsumerSeekCallback> Deprecated, for removal: This API element is subject to removal in a future version.Replaced bygetTopicsAndCallbacks()
protected List<ConsumerSeekAware.ConsumerSeekCallback>
getSeekCallbacksFor
(org.apache.kafka.common.TopicPartition topicPartition) Return the callbacks for the specified topic/partition.protected Map<org.apache.kafka.common.TopicPartition,
List<ConsumerSeekAware.ConsumerSeekCallback>> The map of callbacks for all currently assigned partitions.void
onPartitionsAssigned
(Map<org.apache.kafka.common.TopicPartition, Long> assignments, ConsumerSeekAware.ConsumerSeekCallback callback) When using group management, called when partition assignments change.void
onPartitionsRevoked
(Collection<org.apache.kafka.common.TopicPartition> partitions) When using group management, called when partition assignments are revoked.void
Register the callback to use when seeking at some arbitrary time.void
Seek all assigned partitions to the beginning.void
Seek all assigned partitions to the end.void
seekToTimestamp
(long time) Seek all assigned partitions to the offset represented by the timestamp.void
Called 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, wait
Methods inherited from interface org.springframework.kafka.listener.ConsumerSeekAware
onFirstPoll, onIdleContainer
-
Constructor Details
-
AbstractConsumerSeekAware
public AbstractConsumerSeekAware()
-
-
Method Details
-
registerSeekCallback
Description copied from interface:ConsumerSeekAware
Register the callback to use when seeking at some arbitrary time. When used with aConcurrentMessageListenerContainer
or the same listener instance in multiple containers listeners should store the callback in aThreadLocal
or a map keyed by the thread.- Specified by:
registerSeekCallback
in interfaceConsumerSeekAware
- 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 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:ConsumerSeekAware
When using group management, called when partition assignments are revoked. Listeners should discard any callback saved fromConsumerSeekAware.registerSeekCallback(ConsumerSeekCallback)
on this thread.- Specified by:
onPartitionsRevoked
in interfaceConsumerSeekAware
- 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 interfaceConsumerSeekAware
-
getSeekCallbackFor
@Deprecated(since="3.3", forRemoval=true) @Nullable protected ConsumerSeekAware.ConsumerSeekCallback getSeekCallbackFor(org.apache.kafka.common.TopicPartition topicPartition) Deprecated, for removal: This API element is subject to removal in a future version.Replaced bygetSeekCallbacksFor(TopicPartition)
Return the callback for the specified topic/partition.- Parameters:
topicPartition
- the topic/partition.- Returns:
- the callback (or null if there is no assignment).
-
getSeekCallbacksFor
@Nullable protected List<ConsumerSeekAware.ConsumerSeekCallback> getSeekCallbacksFor(org.apache.kafka.common.TopicPartition topicPartition) Return the callbacks for the specified topic/partition.- Parameters:
topicPartition
- the topic/partition.- Returns:
- the callbacks (or null if there is no assignment).
- Since:
- 3.3
-
getSeekCallbacks
@Deprecated(since="3.3", forRemoval=true) protected Map<org.apache.kafka.common.TopicPartition,ConsumerSeekAware.ConsumerSeekCallback> getSeekCallbacks()Deprecated, for removal: This API element is subject to removal in a future version.Replaced bygetTopicsAndCallbacks()
The map of callbacks for all currently assigned partitions.- Returns:
- the map.
-
getTopicsAndCallbacks
protected Map<org.apache.kafka.common.TopicPartition,List<ConsumerSeekAware.ConsumerSeekCallback>> getTopicsAndCallbacks()The map of callbacks for all currently assigned partitions.- Returns:
- the map.
- Since:
- 3.3
-
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
-
getSeekCallbacksFor(TopicPartition)