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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.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
Java Consumer.endoffset在卡夫卡中是如何工作的?_Java_Apache Kafka_Kafka Consumer Api_Spring Kafka - Fatal编程技术网

Java Consumer.endoffset在卡夫卡中是如何工作的?

Java Consumer.endoffset在卡夫卡中是如何工作的?,java,apache-kafka,kafka-consumer-api,spring-kafka,Java,Apache Kafka,Kafka Consumer Api,Spring Kafka,假设有一个计时器任务无限期地运行,它迭代kafka集群中的所有使用者组,并为每个组的所有分区输出滞后、提交偏移量和结束偏移量。与Kafka console消费组脚本的工作方式类似,只是它适用于所有组 差不多 单个使用者-不工作-不返回某些提供的主题分区的偏移量(例如提供的10个-返回的5个偏移量) 消费者; 静止的{ consumer=createConsumer(); } 运行(){ List groupIds=getConsumerGroups(); for(字符串groupId:group

假设有一个计时器任务无限期地运行,它迭代kafka集群中的所有使用者组,并为每个组的所有分区输出滞后、提交偏移量和结束偏移量。与Kafka console消费组脚本的工作方式类似,只是它适用于所有组

差不多

单个使用者-不工作-不返回某些提供的主题分区的偏移量(例如提供的10个-返回的5个偏移量)

消费者;
静止的{
consumer=createConsumer();
}
运行(){
List groupIds=getConsumerGroups();
for(字符串groupId:groupId){
List TopicPartitions=GetTopicProperties(groupId);
consumer.endOffsets(TopicPartitions);--不起作用-某些组的某些分区缺少偏移量(in 10-out 5)
}
}
多消费者-工作

run() { 
   List<String> groupIds = getConsumerGroups();
   for(String groupId: groupIds) {
        List<TopicParition> topicParitions =  getTopicParitions(groupId);
        Consumer consumer = createConsumer();
        consumer.endOffsets(topicParitions); This works!!!
   }
 }
run(){
List groupIds=getConsumerGroups();
for(字符串groupId:groupId){
List TopicPartitions=GetTopicProperties(groupId);
Consumer=createConsumer();
consumer.endoffset(主题分区);这很有效!!!
}
}
版本:卡夫卡客户端2.0.0

我是否错误地使用了消费者api?理想情况下,我想使用单一消费者


如果你需要更多的细节,请告诉我

我想你就快到了。首先收集所有感兴趣的主题分区,然后发出
consumer.endOffsets
命令

请记住,我还没有尝试运行它,但类似的操作应该会起作用:

run() { 
   Consumer consumer = createConsumer();
   List<String> groupIds = getConsumerGroups();
   List<TopicPartition> topicPartitions = new ArrayList<>();

   for (String groupId: groupIds) {
        topicPartitions.addAll(getTopicPartitions(groupId));
   }

   consumer.endOffsets(topicPartitions); 
}
run(){
Consumer=createConsumer();
List groupIds=getConsumerGroups();
List topicPartitions=new ArrayList();
for(字符串groupId:groupId){
addAll(getTopicPartitions(groupId));
}
消费者。内偏移(主题分区);
}

这是
Fetcher.fetchOffsetsByTimes()
中的一个错误,特别是在
groupListOffsetRequests
方法中,在该方法中,逻辑没有添加用于重试的分区,而请求分区偏移的前导未知或不可用

当我们请求
endoffsets
时,在所有消费者组分区中使用单个消费者时,这一点更为明显。对于没有领导者信息的主题分区,由于该错误,该分区被取消或不可用

后来,我意识到从每个消费者组中提取主题分区不是一个好主意,而是更改为从
AdminClient.listTopics&AdminClient.describeTopics
中读取主题分区,并将所有内容一次性传递给
consumer.endOffsets

尽管这并不能完全解决这个问题,因为主题/分区在多次运行之间可能仍然不可用或未知


更多信息请参见-&。此问题已修复,计划在2.1.0版本发布。

谢谢。当我使用第一个代码段中所示的单个使用者时,为什么您认为consumer.endoffset不会返回所有分区的偏移量?
run() { 
   Consumer consumer = createConsumer();
   List<String> groupIds = getConsumerGroups();
   List<TopicPartition> topicPartitions = new ArrayList<>();

   for (String groupId: groupIds) {
        topicPartitions.addAll(getTopicPartitions(groupId));
   }

   consumer.endOffsets(topicPartitions); 
}