Kafka python consumers re-reading all the part

2019-08-26 05:40发布

问题:

I created kafka partitions, but when I run multiple consumers all the consumers are reading the same message of all the partitions. Here goes my sample code.

from kafka import KafkaClient, SimpleConsumer 
from kafka import KafkaConsumer 
from sys 
import argv 
import time 
consumer = KafkaConsumer("abc", group_id='my-group', bootstrap_servers=['my-server']) 
for message in consumer: 
       #time.sleep(6) 
       print "PARTITION "+str(message[1])+" OFFSET: "+str(message[2])+"\t MSG: "+str(message[4])
       consumer.commit()