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

后端 未结 4 690
北恋
北恋 2021-01-07 22:44

I want to delete a Kakfa consumer group so that when the application creates a consumer and subscribes to a topic it can start at the beginning of the topic data.

Th

相关标签:
4条回答
  • 2021-01-07 22:56

    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.

    0 讨论(0)
  • 2021-01-07 23:06

    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

    0 讨论(0)
  • 2021-01-07 23:07

    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

    0 讨论(0)
  • 2021-01-07 23:10

    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));

    0 讨论(0)
提交回复
热议问题