Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the group commit offset from kafka(0.10.x)

Tags:

apache-kafka

The offsets informations of the group were stored in zookeeper before. Now, in the Kafka Cluster (0.10.x), the offsets informations are stored in the topic which's name is __consumer_offsets.

But how could I get the offsets information of the group which I specified?

like image 833
Matt Avatar asked Dec 12 '16 08:12

Matt


People also ask

How do you check the offset of a topic in Kafka?

Short Answer. If your Kafka topic is in Confluent Cloud, use the kafka-console-consumer command with the --partition and --offset flags to read from a specific partition and offset. You can also read messages from a specified partition and offset using the Confluent Cloud Console: Run it.

What is commit offset in Kafka?

It commits the offset, indicating that all the previous records from that partition have been processed. So, if a consumer stops and comes back later, it restarts from the last committed position (if assigned to that partition again). Note that this behavior is configurable.

How do you manually commit offset in Kafka?

Method Summary Manually assign a list of partition to this consumer. Get the set of partitions currently assigned to this consumer. Close the consumer, waiting indefinitely for any needed cleanup. Commit offsets returned on the last poll() for all the subscribed list of topics and partition.


1 Answers

For active groups, invoke command below to retrieve the offsets:

bin/kafka-consumer-groups.sh --bootstrap-server broker1:9092 --describe --group test-consumer-group

For inactive groups, first get the target offset topic partition number by calculating Math.abs(groupId.hashCode()) % 50, then invoke:

bin/kafka-simple-consumer-shell.sh --topic __consumer_offsets --partition <calculated number> --broker-list broker1:9092 --formatter "kafka.coordinator.GroupMetadataManager\$OffsetsMessageFormatter"

to find offsets for the groups.

like image 67
amethystic Avatar answered Oct 21 '22 11:10

amethystic