Getting GroupNotEmptyException when trying to delete a consumer group in Kafka

Viewed 5782

I executed

"kafka-consumer-groups --bootstrap-server localhost:9092 --list" 

and this results in one group being displayed: console-consumer-961

I then tried to delete this group:

kafka-consumer-groups --bootstrap-server localhost:9092 --delete --group console-consumer-961

But this results in an exception:

Error: Deletion of some consumer groups failed:
* Group 'console-consumer-961' could not be deleted due to: java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.GroupNotEmptyException: The group is not empty.

I guess this group was created when I ran kafka-console-consumer.bat, but now this consumer is not running. How can I delete this consumer group?

2 Answers

You can validate the state of a consumer group by using the kafka-consumer-groups command line tool.

bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group console-consumer-961 --state

This will show you the state of the consumer. If it is not empty, Kafka will not allow to delete that group. If it still shows that your console consumer is running you need to make sure to properly shut it down (usually by CTRL+C)

When you delete a topic, offset information is now correctly reset. So when you create a topic with the same name, consumers start from the beginning of the new data.

you still can't delete new style consumer groups with the Kafka-consumer-groups tool, but your underlying issue is solved.

Before Kafka 0.10.2, there were hacks, but no clean solution to this issue.

Related