How do I delete a Kafka Consumer Group to reset offsets?

血红的双手。 提交于 2019-12-01 03:34:15

In Kafka 0.11 (or Confluent 3.3) you can reset the offsets of any existing consumer group without having to delete the topic. In fact you can change the offsets to any absolute offset value or timestamp or any relative position as well.

These new functions are all added with the new --reset-offsets flag on the kafka-consumer-groups command line tool.

See KIP-122 details here https://cwiki.apache.org/confluence/display/KAFKA/KIP-122%3A+Add+Reset+Consumer+Group+Offsets+tooling

This can be done with Kafka 1.1.x. From the documentation:

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

Upgrading to the just released Confluent Platform 3.2 with Kafka 0.10.2 solved my underlying issue. When I delete a topic, offset information is now correctly reset. So when I create a topic with the same name, consumers start from the beginning of the new data.

I still can't delete new style consumer groups with the kafka-consumer-groups tool, but my underlying issue is solved.

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

If you use Java client, you can first get the beginning offset.

TopicPartition partition = new TopicPartition("YOUR_TOPIC", YOUR_PARTITION);
Map<TopicPartition, Long> map = consumer.beginningOffsets(Collections.singleton(partition));

And the offset that consumer using to start processing, (if not delete the consumer group).

Long committedOffset = consumer.committed(partition).offset();

Now, if you think start from committedOffset is ok, just poll records. if you want the beginning offset, consumer.seek(partition, map.get(partition));

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!