I am running consumer using KafkaMessageListenerContainer.I need to stop the consumer on the topic's last message.How can i identify particular message is the last message in the topic.
Asked
Active
Viewed 910 times
1 Answers
0
You can get it with the following shell command (remove --partition
parameter to get offsets for all topic's partitions):
./bin/kafka-run-class kafka.tools.GetOffsetShell --broker-list <host>:<port> --topic <topic-name> --partition <partition-number> --time -1
As you can see, this is using the GetOffsetShell
[0] object that you may use to get the last message offset and compare it with record's offset.
[0] https://github.com/apache/kafka/blob/trunk/core/src/main/scala/kafka/tools/GetOffsetShell.scala

fvaleri
- 638
- 1
- 4
- 10
-
I need to get end offset when i am using KafkaMessageListenerContainer from spring-kafka – yamuna chukka Jan 19 '21 at 09:28
-
I don't think there is any API for that in KafkaMessageListenerContainer. So you'll have to figure out how to use the object I mentiond or the CLI command from your Java code. – fvaleri Jan 19 '21 at 10:52
-
1Got the answer from here. https://stackoverflow.com/a/62390164/10305656 – yamuna chukka Jan 19 '21 at 13:04
-
yep, that's a more convenient way – fvaleri Jan 19 '21 at 13:27