有人知道如何在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)
但这是行不通的。所以我试着使用多处理库,但我不能使它工作。
2条答案
按热度按时间pengsaosao1#
组id是每个使用者的唯一id。如果您使用多个使用者订阅同一主题,则必须具有不同的组id,否则只有这些使用者中的一个会收到消息。
r7xajy2e2#
检查该主题有多少个分区。组id中的使用者数量不应超过该组正在使用的主题的分区数量。否则,额外的消费者将继续闲置。还要检查是否为每个使用者分配了不同的clienid/consumerid。