Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache kafka Kafka是从给定偏移量具有多个分区的主题读取的单个使用者_Apache Kafka_Kafka Consumer Api - Fatal编程技术网

Apache kafka Kafka是从给定偏移量具有多个分区的主题读取的单个使用者

Apache kafka Kafka是从给定偏移量具有多个分区的主题读取的单个使用者,apache-kafka,kafka-consumer-api,Apache Kafka,Kafka Consumer Api,我有一个带有2个分区的卡夫卡主题,我想创建一个消费者从给定偏移量读取主题,下面是我用来从给定偏移量(9)读取的示例代码 Properties配置属性=新属性(); configProperties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,“localhost:9092”); configProperties.put(ConsumerConfig.KEY\u反序列化程序\u CLASS\u CONFIG,“org.apache.kafka.commo

我有一个带有2个分区的卡夫卡主题,我想创建一个消费者从给定偏移量读取主题,下面是我用来从给定偏移量(9)读取的示例代码

Properties配置属性=新属性();
configProperties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,“localhost:9092”);
configProperties.put(ConsumerConfig.KEY\u反序列化程序\u CLASS\u CONFIG,“org.apache.kafka.common.serialization.StringDeserializer”);
configProperties.put(ConsumerConfig.VALUE\u反序列化程序\u CLASS\u CONFIG,“org.apache.kafka.common.serialization.StringDeserializer”);
put(ConsumerConfig.GROUP_ID_CONFIG,“test_consumer_GROUP”);
configProperties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,“最早”);
卡夫卡消费者卡夫卡消费者=新卡夫卡消费者(配置属性);
kafkaConsumer.subscribe(Arrays.asList(topicName),new ConsumerBalanceListener()){
已撤销分区上的公共void(集合分区){
}
已签名的分区上的公共void(集合分区){
用于(TopicPartition TopicPartition:partitions){
consumer.seek(主题分区,9);
}
}
});
试一试{
while(true){
消费者记录记录=kafkaConsumer.poll(100);
对于(消费者记录:记录){
System.out.println(record.topic()+”、“+record.partition()+”、“+record.offset()+”、“+record.value());
}
}
}捕获(WakeupException ex){
System.out.println(“捕获异常”+ex.getMessage());
}最后{
kafkaConsumer.close();
}
但我看到了以下错误

org.apache.kafka.clients.consumer.internals.Fetcher -  Fetch offset 9 is out of range for parition test-topic_partitions-0, resetting offset
org.apache.kafka.clients.consumer.internals.Fetcher -  Resetting offset for partition test-topic_partitions-0 to offset 
我使用的是maven依赖项

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version>2.1.0</version>
</dependency>

org.apache.kafka
卡夫卡客户
2.1.0
还有一点要提的是,为本主题配置的
delete.retention.ms
为86400000(1天),而
retention.ms
为17280000(2天)


有人能帮助解决此错误吗?

此错误意味着分区在偏移量9处没有记录。 因此,要么:

  • 分区中当前只有不到9条记录
  • 保留策略已删除至少9条记录
您可以使用和查找分区中的最小偏移量和最大偏移量。如果试图寻找超出此范围的偏移量,则会触发重置策略
auto.offset.reset
以查找有效偏移量