如何更改主题的起始偏移量? [英] How to change start offset for topic?
问题描述
是否可以更改新主题的开始偏移量?我想创建一个新主题,并从偏移量 10000
开始阅读.怎么样?
It is possible to change the start offset for a new topic? I would like to create a new topic and start reading from the offset 10000
. How?
推荐答案
您可以在zookeeper shell的帮助下进行此操作.Kafka使用Zookeeper来跟踪消费者的偏移量.
You can do this with the help of the zookeeper shell. Kafka uses zookeeper to track the consumer offsets.
转到kafka bin目录并调用zookeeper shell.(我的kafka版本是0.8.0)
Go to kafka bin directory and invoke zookeeper shell.(my kafka version is 0.8.0)
./zookeeper-shell.sh localhost:2181
现在使用zookeeper get命令
Now use the zookeeper get command
get /consumers/consumer_group_id/offsets/topic/0
显示类似
2043
cZxid = 0x4d
ctime = Wed Mar 18 03:56:32 EDT 2015
...
这里2043是消耗的最大偏移量.使用zookeeper set命令将其设置为所需值
Here 2043 is the maximum offset consumed. Set it to desired value by using zookeeper set command
set /consumers/consumer_group_id/offsets/topic/0 10000
路径的框架格式为/consumers/[consumer_group_id]/offsets/[topic]/[partition_id].
您将不得不用适当的消费者组,主题和分区ID代替.
The path is framed like this /consumers/[consumer_group_id]/offsets/[topic]/[partition_id].
You will have to substitute with appropriate consumer group, topic and partition id.
*此外,由于您提到它是kafka的新实例,所以我不确定消费者是否可以建立联系并创建消费者组.
*Also since you mentioned it's a new instance of kafka, I am not sure whether consumers would have connected and consumer groups created.
这篇关于如何更改主题的起始偏移量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!