1、場景
a)有時消費端邏輯修改,需要重復消費數據,需要將offset設置到指定位置。
2、實現
kafka版本:0.11.*
KIP-122: Add Reset Consumer Group Offsets tooling
樣例:
./kafka-consumer-groups.sh --bootstrap-server ip:9092 --group groupName --reset-offsets --to-offset 1000 --topic topicName --execute
3、問題
--reset-offsets 是從0.11.*后支持,如果是0.10.*的版本可以如下操作:
a.下載0.11.*或更新版本
b.使用0.11.*或更新版本的腳本即可(kafka-consumer-groups.sh),不過有的功能可能會提示接口版本問題。例如--describe提示kafka服務端接口版本過低。
參考原文:
For ones who want to do the same for Kafka 0.10 you may download Kafka 1.0 binaries which include the script with this new offset reset capabilities, it will work for Kafka 0.10 as well:
wget http://apache-mirror.rbc.ru/pub/apache/kafka/1.0.0/kafka_2.11-1.0.0.tgz
tar -xvf kafka_2.11-1.0.0.tgz
cd kafka_2.11-1.0.0/bin
4、其他配套使用腳本
a.查看消費組list
./kafka-consumer-groups.sh --new-consumer --bootstrap-server ip:9092 --list
b.查看指定消費者的offset
./kafka-consumer-groups.sh --new-consumer --bootstrap-server ip:9092 --describe --group groupName
c.重置offset
./kafka-consumer-groups.sh --bootstrap-server ip:9092 --group groupName --reset-offsets --to-offset 1000 --topic topicName --execute
參考
kafka 0.11 how to reset offsets
how to reset kafka consumer group offset
