查询topic的offset的范围
用下面命令可以查询到topic:Mytopic broker:SparkMaster:9092的offset的最小值:
bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list kafka-server-ip:9092 -topic Mytopic --time -2
输出
DynamicRange:0:1288
查询offset的最大值:
bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list kafka-server-ip:9092 -topic Mytopic --time -1
输出
DMytopic:0:7885
从上面的输出可以看出topic:Mytopic只有一个partition:0 offset范围为:[1288,7885]
设置consumer group的offset
启动zookeeper client
/zookeeper/bin/zkCli.sh
通过下面命令设置consumer group:ConsumerGroupName topic:Mytopic partition:0的offset为1288:
set /consumers/ConsumerGroupName/offsets/Mytopic/0 1288
注意如果你的kafka设置了zookeeper root,比如为/kafka,那么命令应该改为:
set /kafka/consumers/ConsumerGroupName/offsets/Mytopic/0 1288