有人知道如何在Python中使用相同的组ID来运行多个消费者吗? 我试过以下Python中具有相同组ID的多个消费者
a = Consumer({'bootstrap.servers': 'localhost:9092', 'group.id': 'dd1',
'default.topic.config': {'auto.offset.reset': 'smallest'}})
b = Consumer({'bootstrap.servers': 'localhost:9092', 'group.id': 'dd1',
'default.topic.config': {'auto.offset.reset': 'smallest'}})
c = Consumer({'bootstrap.servers': 'localhost:9092', 'group.id': 'dd1',
'default.topic.config': {'auto.offset.reset': 'smallest'}})
a.subscribe([topic_to_read])
b.subscribe([topic_to_read])
c.subscribe([topic_to_read])
running = True
while running:
msg1 = a.poll(timeout=timeout)
msg2 = b.poll(timeout=timeout)
msg3 = c.poll(timeout=timeout)
但是,这是行不通的。 所以我试过使用多处理库,但我无法使它工作。
你为什么说它不工作。你期望什么把他们放在同一个团队中的行为? 您在topic_to_read中有多少个分区? –