Kafka给出NoSuchElementException

时间:2016-04-29 12:39:58

标签: spring-integration apache-kafka kafka-consumer-api kafka-producer-api

我通过Java代码创建了多个分区的主题,如下所述。

<div ng-repeat="look_up in lookup">
    <div class="title" 
         ng-click="itemSelected = $index;">

         {{look_up.name}} - {{look_up.status}}
    </div>
    <div ng-if="itemSelected == $index">
        <table>
            <tr ng-repeat="">  ...  </tr>
        </table>
    </div>
</div>

一旦java代码成功运行,我检查了kafka console use

主题的描述
private void existOrCreateTopicsWithPartition(Properties prop) {
    String kafkaServer = prop.getProperty(KafkaProducerKey.BOOTSTRAP_SERVERS_CONFIG.getKey());

    int replicationFactor = kafkaServer.split(BROKER_SEPERATION_REGEX).length;
    int totalPartionCount;
    ZkClient zkClient = new ZkClient(kafkaServer, Integer.MAX_VALUE, Integer.MAX_VALUE,new SerializableSerializer());
    ZkUtils zkutils = new  ZkUtils(zkClient, new ZkConnection(kafkaServer), false);
    String  producerTopics = prop.getProperty(KafkaProducerKey.PRODUCER_TOPICS.getKey());
    String topics[] = producerTopics.split(TOPICS_SEPERATOR_REGEX);
    for(String topic : topics){
        topic = topic.trim();

        if(!AdminUtils.topicExists(zkutils, topic)){
            totalPartionCount = Integer.valueOf(prop.getProperty(topic+PARTITION_KEY, "1"));
            AdminUtils.createTopic(zkutils, topic, totalPartionCount, replicationFactor, new Properties());
        }
    }


}

哪个给出错误而不是结果。

org@org-VirtualBox:~/Downloads/kafka_2.9.2-0.8.1$ bin/kafka-topics.sh --zookeeper  192.168.56.101:2181 --topic sms_cat_2 --describe

如果我运行在Spring-Integration的帮助下创建的消费者,它会在无限循环中发出警告,看起来像

Error while executing topic command next on empty iterator  java.util.NoSuchElementException: next on empty iterator
at scala.collection.Iterator$$anon$3.next(Iterator.scala:27)
at scala.collection.Iterator$$anon$3.next(Iterator.scala:25)
at scala.collection.IterableLike$class.head(IterableLike.scala:90)
at scala.collection.immutable.Map$EmptyMap$.head(Map.scala:88)
at kafka.admin.TopicCommand$$anonfun$describeTopic$1.apply(TopicCommand.scala:147)
at kafka.admin.TopicCommand$$anonfun$describeTopic$1.apply(TopicCommand.scala:137)
at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:60)
at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
at kafka.admin.TopicCommand$.describeTopic(TopicCommand.scala:137)
at kafka.admin.TopicCommand$.main(TopicCommand.scala:58)
at kafka.admin.TopicCommand.main(TopicCommand.scala)

更新:以下提及命令的日志。

WARN  NetworkClient:582 - Error while fetching metadata with correlation id 1 : {sms_cat_1=LEADER_NOT_AVAILABLE,  sms_cat_2=INVALID_TOPIC_EXCEPTION}

有任何建议。

由于

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,我在Kafka上描述了这个主题,发现其中一个分区是Leader: -1