Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Getting kafka consumer offsets of a consumer group for a given topic in java?

Getting kafka consumer offsets of a consumer group for a given topic in java?

New Contributor

Hi,

I am trying to write a java program that monitors the kafka consumer and end offset values and send alerts if it does not update for a given period of time. So i was using the consumer.getCommitedOffsets() method in the Kafka consumer API in java. But this does not seem to be the correct consumer offset value or maybe not the consumer offset for this consumer group. Can anyone tell me how to get the value of consumer offsets in kafka for a consumer group and particular topic?

4 REPLIES 4
Highlighted

Re: Getting kafka consumer offsets of a consumer group for a given topic in java?

Super Guru

@ROHIT AILA

Have you tried using consumer.position(TopicPartition partition)? or run the following script from your java program. You can also run the script with zookeeper instead of bootsrap-server.

kafka-consumer-groups.sh --bootstrap-server <broker-host>:9092 --new-consumer --group groupname --describe

Re: Getting kafka consumer offsets of a consumer group for a given topic in java?

New Contributor

@mqureshi I tried using the consumer.position(TopicPartition partition) method. But this does not seem to give the correct value either. I know how to get them in the command line. So i am comparing the values in zookeeper to the one in java method. My goal is to get those values in Java.

Re: Getting kafka consumer offsets of a consumer group for a given topic in java?

Super Guru

@ROHIT AILA

I understand. That's why, I think you need to call kafka-consumer-group.sh script from your java program to get what you are looking for.

Re: Getting kafka consumer offsets of a consumer group for a given topic in java?

Super Collaborator

kafka-consumer-groups.sh calls ConsumerGroupCommand

Please take a look at the following method:

ConsumerGroupCommand#getPartitionOffsets

Don't have an account?
Coming from Hortonworks? Activate your account here