怎样清空指定kafka中topic中的数据呢?使用kafka-delete-records.sh脚本,如下:
kafka-delete-records.sh --bootstrap-server 192.168.23.121:9092 --offset-json-file DELETE_temp0208.json
其中DELETE_temp0208.json的内容如下:
{"partitions":[{"topic": "temp0208", "partition": 0, "offset": -1}]}
验证如下:
1)新建topic,并发送数据
[root@localhost ~]# kafka-console-producer.sh --broker-list 192.168.23.121:9092 --topic temp0208
>111111
>22222
>333
>44
>5
>
2)开启消费
[root@localhost ~]# kafka-console-consumer.sh --bootstrap-server 192.168.23.121:9092 --topic temp0208 --partition 0 --offset earliest
111111
22222
333
44
5
3)执行清空命令后 再次消费 无法消费到数据
[root@localhost ~]# kafka-delete-records.sh --bootstrap-server 192.168.23.121:9092 --offset-json-file DELETE_temp0208.json
Executing records delete operation
Records delete operation completed:
partition: temp0208-0 low_watermark: 16
[root@localhost ~]# kafka-console-consumer.sh --bootstrap-server 192.168.23.121:9092 --topic temp0208 --partition 0 --offset earliest