How can I consume data from specific partitions in Kafka using Confluent Python?

huangapple go评论63阅读模式
英文:

How can I consume data from specific partitions in Kafka using Confluent Python?

问题

我尝试了这段代码,但它也从其他分区消费数据,但我的要求是只从1和2分区消费数据。

ConsumerKafka.subscribe(topic_list)
ConsumerKafka.assign([TopicPartition(topic_name, 1, 2)])

英文:

I tried this code but it is consuming from other partitions as well but my req is to consume from 1 and 2 partition

          ConsumerKafka.subscribe(topic_list)
          ConsumerKafka.assign([TopicPartition(topic_name, 1, 2)])

答案1

得分: 0

你需要移除订阅调用以仅消费特定分区

另外,你需要一个包含两个元素的列表

[TopicPartition(topic_name, p) for p in [1,2]]

英文:

You need to remove subscribe call to consume from only specific partitions

Also, you need two element list

[TopicPartition(topic_name, p) for p in [1,2]]

huangapple
  • 本文由 发表于 2023年5月29日 20:24:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76357353.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定