嗨,以下是我的消费者的代码,
$conf->set('group.id','commonqueue2');
$conf->set('offset.store.method', 'broker');
$rk = new \RdKafka\Consumer($conf);
$rk->addBrokers($kafka_servers);
$topicConf = new \RdKafka\TopicConf();
$topicConf->set('auto.commit.interval.ms',1000);
$topicConf->set('offset.store.method', 'broker');
$topicConf->set('auto.offset.reset', 'smallest');
$topic = $rk->newTopic("registration17", $topicConf);
$topic->consumeStart(0,RD_KAFKA_OFFSET_STORED);
while (true) {
$message = $topic->consume(0,1000);
//store offset to broker
$topic->offsetStore($message->partition,$message->offset);
$message_offset = $message->offset;
echo $message_data = $message->payload;
}//end of while loop
在上面的程序中,如何在执行下面的代码
之前找到最后存储的偏移量$topic->consumeStart(0,RD_KAFKA_OFFSET_STORED);
答案 0 :(得分:0)
有两种方法可以获得最新的偏移量: 1.来自zookeeper Shell 通过使用coomand get / consumers // offsets // num_of_partitions 如需帮助,请使用以下链接:https://cwiki.apache.org/confluence/display/KAFKA/Kafka+data+structures+in+Zookeeper
2.要检索最新的偏移量,我们甚至可以使用命令:bin / kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --group --zookeeper: - topic