Purge Kafka Topic

后端 未结 19 2293
慢半拍i
慢半拍i 2020-11-28 00:06

Is there a way to purge the topic in kafka?

I pushed a message that was too big into a kafka message topic on my local machine, now I\'m getting an

相关标签:
19条回答
  • 2020-11-28 00:52

    While the accepted answer is correct, that method has been deprecated. Topic configuration should now be done via kafka-configs.

    kafka-configs --zookeeper localhost:2181 --entity-type topics --alter --add-config retention.ms=1000 --entity-name MyTopic
    

    Configurations set via this method can be displayed with the command

    kafka-configs --zookeeper localhost:2181 --entity-type topics --describe --entity-name MyTopic
    
    0 讨论(0)
  • 2020-11-28 00:54

    To purge the queue you can delete the topic:

    bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic test
    

    then re-create it:

    bin/kafka-topics.sh --create --zookeeper localhost:2181 \
        --replication-factor 1 --partitions 1 --topic test
    
    0 讨论(0)
  • 2020-11-28 00:56

    Following @steven appleyard answer I executed the following commands on Kafka 2.2.0 and they worked for me.

    bin/kafka-configs.sh --zookeeper localhost:2181 --entity-type topics --entity-name <topic-name> --describe
    
    bin/kafka-configs.sh --zookeeper localhost:2181 --entity-type topics --entity-name <topic-name> --alter --add-config retention.ms=1000
    
    bin/kafka-configs.sh --zookeeper localhost:2181 --entity-type topics --entity-name <topic-name> --alter --delete-config retention.ms
    
    0 讨论(0)
  • 2020-11-28 00:58

    Tested in Kafka 0.8.2, for the quick-start example: First, Add one line to server.properties file under config folder:

    delete.topic.enable=true
    

    then, you can run this command:

    bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic test
    
    0 讨论(0)
  • 2020-11-28 01:00

    To clean up all the messages from a particular topic using your application group (GroupName should be same as application kafka group name).

    ./kafka-path/bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic topicName --from-beginning --group application-group

    0 讨论(0)
  • 2020-11-28 01:01

    From kafka 1.1

    Purge a topic

    bin/kafka-configs.sh --zookeeper localhost:2181 --alter --entity-type topics --entity-name tp_binance_kline --add-config retention.ms=100
    

    wait 1 minute, to be secure that kafka purge the topic remove the configuration, and then go to default value

    bin/kafka-configs.sh --zookeeper localhost:2181 --alter --entity-type topics --entity-name tp_binance_kline --delete-config retention.ms
    
    0 讨论(0)
提交回复
热议问题