繁体   English   中英

Python中具有相同组ID的多个使用者

[英]Multiple consumers with same group id in Python

有人知道如何在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)

但这是行不通的。 因此,我尝试使用多处理库,但无法使其工作。

组ID是每个消费者的唯一ID。 如果您要与多个使用者一起订阅同一主题,则必须具有不同的组ID,否则这些使用者中只有一个会收到消息。

检查该主题的分区数量。 组ID中的使用者数量不应超过该组所使用的主题的分区数量。 否则,额外的消费者将保持闲置状态。 还请检查是否要为每个消费者分配不同的客户编号/消费者编号。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM