使用pykafka读取特定记录

时间:2018-05-16 10:19:18

标签: python apache-kafka pykafka

我想在Kafka中存储大文件,使用有关该记录的元数据来检索它们。

所以我发送包含主题,partition_id,offset的消息,然后我尝试以这种方式检索文件:

def retrieve_file_from_kafka(topic_name, partition_id, offset):
    client = KafkaClient(hosts=BROKER_ADDRESS, broker_version="0.10.1.0")
    topic = client.topics[bytes(topic_name, "UTF-8")]

    consumer = topic.get_balanced_consumer(
    consumer_group=bytes("file_retrieve" + topic_name + str(partition_id) + str(offset), "UTF-8"))
    consumer.reset_offsets([(topic.partitions[partition_id], offset)])
    return consumer.consume()

它不起作用,只打印:

Offset reset for partition 0 to timestamp 8 failed. Setting partition 0's internal counter to 8

此错误非常隐秘,它发生在reset_offsets上。当我尝试使用时,该进程随后等待rebalancing_lock。我做错了什么?

0 个答案:

没有答案