小编art*_*ini的帖子

使用 Python 读取特定的 Kafka 主题

我的主题有 3 个分区,我尝试使用以下代码从每个特定分区读取内容

from kafka import KafkaConsumer, TopicPartition

brokers = 'localhost:9092'
topic = 'b3'

m = KafkaConsumer(topic, bootstrap_servers=['localhost:9092'])
par = TopicPartition(topic=topic, partition=1)
m.assign(par)
Run Code Online (Sandbox Code Playgroud)

但我收到此错误:

    raise IllegalStateError(self._SUBSCRIPTION_EXCEPTION_MESSAGE)
kafka.errors.IllegalStateError: IllegalStateError: You must choose only one way to configure your consumer: (1) subscribe to specific topics by name, (2) subscribe to topics matching a regex pattern, (3) assign itself specific topic-partitions.
Run Code Online (Sandbox Code Playgroud)

有人可以帮我解决这个问题吗?

python apache-kafka kafka-python

2
推荐指数
1
解决办法
5137
查看次数

标签 统计

apache-kafka ×1

kafka-python ×1

python ×1