SpringSpring Kafka Advanced
How does @KafkaListener handle partition assignment and offset control?
Reference answer
By default, with topics or topicPattern, Kafka assigns partitions automatically according to the consumer group. For explicit assignment use topicPartitions: @KafkaListener(topicPartitions = @TopicPartition(topic='my-topic', partitions={'0','1'}, partitionOffsets=@PartitionOffset(partition='2', initialOffset='100'))). You can specify each partition in either partitions or partitionOffsets, not both; the '*' wildcard in a @PartitionOffset applies an initial offset to all assigned partitions, and partitions accepts ranges such as '0-5, 7'. Since 3.2, @PartitionOffset also supports seekPosition (BEGINNING, END, TIMESTAMP). For programmatic seeks, implement ConsumerSeekAware: onPartitionsAssigned(assignments, callback) is called after assignment (also with manual assignment) and you use the callback argument to seek, seekToBeginning, seekToEnd, seekRelative or seekToTimestamp(topic, partition, timestamp). AbstractConsumerSeekAware tracks the callbacks and adds helpers such as seekToTimestamp(long) for all assigned partitions. These are useful for replay scenarios or consuming historical data from a specific point.
Expected key concepts: topicPartitions, @TopicPartition, @PartitionOffset, initialOffset, ConsumerSeekAware, onPartitionsAssigned, seekToTimestamp, seekToBeginning, AbstractConsumerSeekAware, replay
How did that feel?
Your own verdict, not the score. It shows up next to this question in the list, so you can come back to the shaky ones.