python和kafka KeyError:-1

时间:2014-02-26 08:34:01

标签: python apache-kafka

Python kafka不起作用。有什么理由吗?我的意思是我无法连接到kafka,我收到错误?是否有适用于0.8的kafka客户端?我的意思是这是一个全新的服务器。我刚启动它。
我正在使用https://github.com/mumrah/kafka-python

from kafka.client import KafkaClient
kafka = KafkaClient(kafka_domain, 9092)


Traceback (most recent call last):
  File "/home/ubuntu/workspace/rtbhui-devops/simulations/pixel_druid_simulations.py", line 36, in <module>
    kafka = KafkaClient(kafka_domain, 9092)
  File "/usr/local/lib/python2.7/dist-packages/kafka/client.py", line 38, in __init__
    self.load_metadata_for_topics()  # bootstrap with all metadata
  File "/usr/local/lib/python2.7/dist-packages/kafka/client.py", line 247, in load_metadata_for_topics
    self.topics_to_brokers[topic_part] = brokers[meta.leader]
KeyError: -1

在kafka日志中,我看到了以下内容。

[2014-02-26 08:36:21,471] INFO Closing socket connection to /222.127.xxx.xxx. (kafka.network.Processor)
[2014-02-26 08:40:30,801] ERROR [KafkaApi-1393401480] Error while fetching metadata for partition [topic-pixel,0] (kafka.server.KafkaApis)
kafka.common.LeaderNotAvailableException: Leader not available for partition [topic-pixel,0]
    at kafka.server.KafkaApis$$anonfun$17$$anonfun$20.apply(KafkaApis.scala:474)
    at kafka.server.KafkaApis$$anonfun$17$$anonfun$20.apply(KafkaApis.scala:462)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:206)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:206)
    at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:61)
    at scala.collection.immutable.List.foreach(List.scala:45)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:206)
    at scala.collection.immutable.List.map(List.scala:45)
    at kafka.server.KafkaApis$$anonfun$17.apply(KafkaApis.scala:462)
    at kafka.server.KafkaApis$$anonfun$17.apply(KafkaApis.scala:458)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:206)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:206)
    at scala.collection.immutable.Set$Set1.foreach(Set.scala:81)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:206)
    at scala.collection.immutable.Set$Set1.map(Set.scala:68)
    at kafka.server.KafkaApis.handleTopicMetadataRequest(KafkaApis.scala:458)
    at kafka.server.KafkaApis.handle(KafkaApis.scala:68)
    at kafka.server.KafkaRequestHandler.run(KafkaRequestHandler.scala:42)
    at java.lang.Thread.run(Thread.java:744)

1 个答案:

答案 0 :(得分:1)

这在kafka-python版本0.9.0中得到修复。这个错误是Kafka Python内部的,而不是kafka服务器,只是涉及处理当前没有领导者的分区(当你自动创建主题时会出现任何新主题,但除此之外在正常操作下相当罕见)< / p>

https://github.com/mumrah/kafka-python/pull/109