简体   繁体   English

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

[英]Multiple consumers with same group id in Python

Does anybody know how to run multiple consumers with same group id in Python? 有人知道如何在Python中使用相同的组ID运行多个使用者吗? I've tried following 我尝试了以下

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)

But this is not working. 但这是行不通的。 So I've tried using multiprocessing lib but I am not able to make it work. 因此,我尝试使用多处理库,但无法使其工作。

A group ID is a unique ID to each consumer. 组ID是每个消费者的唯一ID。 If you are subscribing to a same topic with multiple consumers, you must have different group ID's or else only one of those consumers will get the messages. 如果您要与多个使用者一起订阅同一主题,则必须具有不同的组ID,否则这些使用者中只有一个会收到消息。

Check how many partitions you have for that topic. 检查该主题的分区数量。 The number of consumers within a group id should not exceed the number of partitions of the topic the group is consuming from. 组ID中的使用者数量不应超过该组所使用的主题的分区数量。 Else the extra consumers will remain idle. 否则,额外的消费者将保持闲置状态。 ALSO CHECK IF YOU ARE ASSIGNING DIFFERENT CLIENID/CONSUMERID FOR EACH OF THE CONSUMERS. 还请检查是否要为每个消费者分配不同的客户编号/消费者编号。

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

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