如何更改主题的起始偏移量? [英] 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屋!