2017-10-21 123 views
0

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

但是,这是行不通的。 所以我试过使用多处理库,但我无法使它工作。

+0

你为什么说它不工作。你期望什么把他们放在同一个团队中的行为? 您在topic_to_read中有多少个分区? –

回答

0

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

0

检查您拥有该主题的分区数。组ID消费者的数量不应超过组消费的主题的分区数量。否则额外的消费者将保持闲置。 如果您正在为每个消费者分配不同的CLIENID/CONSUMERID,请检查。

相关问题