Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove a Kafka consumer group from a specific topic?

I changed the consumer-group-id of my web service listening to a Kafka topic. Now, the old group id is still registered to the topic, but there is no consumer with that group id. Therefore, it is lagging. How can I remove a specific consumer group from a specific topic?

I tried this:

kafka-consumer-groups --bootstrap-server kafka01.myserver.com:9092 --topic notification-topic --delete --group old-consumer-group --execute

But it returns: "The consumer does not support topic-specific offset deletion from a consumer group."

Should I remove the consumer group totally? I use the same group id listening to other topics, are they going to be affected?

like image 636
Cagatay Avatar asked Sep 02 '20 11:09

Cagatay


People also ask

How do I delete a consumer group from topic?

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.

Is Kafka consumer group per topic?

Kafka Consumer Groups A consumer group has a unique id. Each consumer group is a subscriber to one or more Kafka topics. Each consumer group maintains its offset per topic partition. If you need multiple subscribers, then you have multiple consumer groups.

Can we delete consumer group?

Delete a consumer-group: 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.

How do I remove something from a Kafka topic?

This can be done using the kafka-delete-records.sh tool to read a configuration file (JSON format) that describes the records we want to be deleted. The example in the listing below can be used to remove all messages from the test-topic created earlier. The contents of the file should be saved as delete-test.


2 Answers

Starting with Kafka 2.4.0 it is possible to delete individual consumer group id offsets from a topic.

The call is very close to what you have already tried, but requires --delete-offsets instead of --delete:

./kafka-consumer-groups.sh \
  --bootstrap-server <bootstrap-server-url> \
  --delete-offsets \
  --group <my-group> \
  --topic <topic-name>

To date this is not reflected in the official documentation (Kafka 2.7.0 and below). However, it is described in a confluence document of improvement proposal KIP-496 that has been implemented and released.

like image 88
summon Avatar answered Oct 06 '22 00:10

summon


You cannot remove a specific group on its own, nor a topic from a group.

Consumer groups remain available based on the retention you've defined for the offsets topic on the broker. There is no performance impact by having lagging groups that are not being consumed.

Note: Every time you use kafka-console-consumer, a brand new group is created.

like image 37
OneCricketeer Avatar answered Oct 06 '22 01:10

OneCricketeer