Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removing a kafka consumer group in zookeeper

I'm using kafka_2.9.2-0.8.1.1 with zookeeper 3.4.6.

Is there a utility that can automatically remove a consumer group from zookeeper? Or can I just remove everything under /consumers/[group_id] in zookeeper? If the latter, is there anything else I'm missing & can this be done with a live system?

Update: As of kafka version 2.3.0, there is a new utility:

> bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --delete --group my-group

Related doc: http://kafka.apache.org/documentation/#basic_ops_consumer_lag

See below for more discussion

like image 404
Foo L Avatar asked Mar 24 '15 22:03

Foo L


People also ask

How do I delete a consumer group from Kafka?

You can delete consumer groups from Kafka instances by using the Kafka command line tool of your Kafka client. NOTE: Ensure that the client uses the same version as the Kafka instance. [root@zk-server-1 bin]# ./kafka-consumer-groups.sh --bootstrap-server 172.31.

When a consumer group is deleted in Kafka?

deletion is only available when the group metadata is stored in zookeeper (old consumer api). With the new consumer API, the broker handles everything including metadata deletion: the group is deleted automatically when the last committed offset for the group expires.

Can I delete __ consumer_offsets?

__consumer_offsets is a kafka internal topic and it is not allowed to be deleted through delete topic command. It contains information about committed offsets for each topic:partition for each group of consumers (groupID). If you want to wipe it out entirely you have to delete the zookeeper dataDir location.

How do I change consumer group in Kafka?

How to change consumer offset? Use the kafka-consumer-groups.sh to change or reset the offset. You would have to specify the topic, consumer group and use the –reset-offsets flag to change the offset.

How to delete a group ID in Kafka manager?

We can't delete a group id in kafka manager by remove the node in zookeeper. However, I have a deprecated consumer group but the topic it consumerd from is still useful. We can see the lag of the consumer group is keep growing.

Why remove zookeeper dependency from Kafka?

Removing the dependency to ZooKeeper from Kafka, improves the scalability and simplifies the architecture of Kafka; however, it is a major change that involves many moving parts. Not including the Alpha (which won’t have an upgrade process), the upgrade path for a post-KIP-500 Kafka release will go through a bridge release.

What are __consumer_offsets in Kafka?

Kafka brokers use an internal topic named __consumer_offsets that keeps track of what messages a given consumer group last successfully processed. As we know, each message in a Kafka topic has a partition ID and an offset ID attached to it.

Where does zookeeper store data?

Data such as the location of partitions and the configuration of topics are stored outside of Kafka itself, in a separate ZooKeeper cluster. In 2019, we outlined a plan to break this dependency and bring metadata management into Kafka itself.


4 Answers

As of v0.9.0, Kafka ships with a suite of tools in the /bin one of which is the kafka-consumer-groups.sh tool. This will delete a consumer group. ./kafka-consumer-groups.sh --zookeeper <zookeeper_url> --delete --group <group-name>

like image 157
eodgooch Avatar answered Oct 19 '22 15:10

eodgooch


For new consumers (which use a kafka topic to manage offsets instead of zookeeper) you cannot delete the group information using kafka's built in tools.

Here is an example of trying to delete the group information for a new style consumer using the kafka-consumer-groups.sh script:

bin/kafka-consumer-groups.sh --bootstrap-server "kafka:9092" --delete --group "indexer" --topic "cleaned-logs"
Option '[delete]' is only valid with '[zookeeper]'. Note that there's no need to delete group metadata for the new consumer as the group is deleted when the last committed offset for that group expires.

Here's the important part of that response:

Note that there's no need to delete group metadata for the new consumer as the group is deleted when the last committed offset for that group expires.

This is kind of annoying from a monitoring perspective (esp. when tracking offsets via something like burrow) because it means that if you change consumer group names in your code you'll keep seeing that old groups are behind on their offsets until those offsets expire.

Hypothetically you could write a tombstone to that topic manually (which is what happens during offset expiration) but I haven't found any tools that make this easy.

like image 32
turtlemonvh Avatar answered Oct 19 '22 15:10

turtlemonvh


you can delete group from kafka by CLI

kafka-consumer-groups --bootstrap-server localhost:9092 --delete --group group_name
like image 21
Rudy Avatar answered Oct 19 '22 15:10

Rudy


Currently, as I know, the only way to remove a Kafka consumer group is manually deleting Zookeeper path /consumers/[group_id].

If you just want to delete a consumer group, there is nothing to worry about manually deleting the Zookeeper path, but if you do it for rewinding offsets, the below will be helpful.

First of all, you should stop all the consumers belongs to the consumer group before removing the Zookeeper path. If you don't, those consumers will not consume newly produced messages and will soon close connections to the Zookeeper cluster.

When you restart the consumers, if you want the consumers to start off from the beginning, give auto.offset.reset property to smallest (or earliest in new Kafka releases). The default value of the property is largest (or latest in new Kafka releases) which makes your restarting consumers read after the largest offset which in turn consuming only newly produced messages. For more information about the property, refer to Consumer Config in the Kafka documentation.

FYI, there is a question How can I rewind the offset in the consumer? in Kafka FAQ, but it gave me not much help.

like image 28
Heejin Avatar answered Oct 19 '22 14:10

Heejin