Class AbstractConsumerSeekAware
- java.lang.Object
-
- org.springframework.kafka.listener.AbstractConsumerSeekAware
-
- All Implemented Interfaces:
ConsumerSeekAware
public abstract class AbstractConsumerSeekAware extends java.lang.Object implements ConsumerSeekAware
Manages theConsumerSeekAware.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 Constructor Description AbstractConsumerSeekAware()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.Map<ConsumerSeekAware.ConsumerSeekCallback,java.util.List<org.apache.kafka.common.TopicPartition>>
getCallbacksAndTopics()
Return the currently registered callbacks and their associatedTopicPartition
(s).protected ConsumerSeekAware.ConsumerSeekCallback
getSeekCallbackFor(org.apache.kafka.common.TopicPartition topicPartition)
Return the callback for the specified topic/partition.protected java.util.Map<org.apache.kafka.common.TopicPartition,ConsumerSeekAware.ConsumerSeekCallback>
getSeekCallbacks()
The map of callbacks for all currently assigned partitions.void
onPartitionsAssigned(java.util.Map<org.apache.kafka.common.TopicPartition,java.lang.Long> assignments, ConsumerSeekAware.ConsumerSeekCallback callback)
When using group management, called when partition assignments change.void
onPartitionsRevoked(java.util.Collection<org.apache.kafka.common.TopicPartition> partitions)
When using group management, called when partition assignments are revoked.void
registerSeekCallback(ConsumerSeekAware.ConsumerSeekCallback callback)
Register the callback to use when seeking at some arbitrary time.void
seekToBeginning()
Seek all assigned partitions to the beginning.void
seekToEnd()
Seek all assigned partitions to the end.void
seekToTimestamp(long time)
Seek all assigned partitions to the offset represented by the timestamp.void
unregisterSeekCallback()
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
onIdleContainer
-
-
-
-
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 aConcurrentMessageListenerContainer
or the same listener instance in multiple containers listeners should store the callback in aThreadLocal
.- Specified by:
registerSeekCallback
in interfaceConsumerSeekAware
- 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 interfaceConsumerSeekAware
- Parameters:
assignments
- the new assignments and their current offsets.callback
- the callback to perform an initial seek after assignment.
-
onPartitionsRevoked
public void onPartitionsRevoked(java.util.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 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
@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 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
-
-