I am using Kafka (kafka-python
) version 3.0.0-1.3.0.0.p0.40. I need to configure the consumer for the topic 'simulation' in Python. When I don't indicate the group_id, i.e. group_id = None it receives messages fine. However if I indicate the group_id, it doesn't receive any messages.
Here's my code in Python:
consumer = KafkaConsumer(bootstrap_servers='XXX.XXX.XXX.XXX:9092',
group_id = 'myTestGroupID', enable_auto_commit = True)
consumer.subscribe(['simulation'])
# not using assign method here as auto_commit is enabled
# partitions = [TopicPartition('simulation',num) for num in range(0,9)]
# consumer.assign([TopicPartition('simulation', partitions[0])])
while not self.stop_event.is_set():
for message in consumer:
print(message)
I tried to search for some default values of group_id in consumer properties files, I've found one cloudera_mirrormaker however nothing changed. I will need to use multiple consumers therefore it's important that I have a group_id and they share the same group_id. In many sources I've found that the group_id can be any string...
When I run the consumer for this topic in the console it works and receives messages
./kafka-console-consumer.sh --bootstrap-server XXX.XXX.XXX.XXX:9092 --topic simulation --from-beginning --consumer-property group.id=myTestGroupID --partition 0
when I'm running kafka-consumer-groups.sh to list all available groups it's empty.
If anyone has an idea why it's stuck in Python, it would be so much appreciated. Thanks a lot
Here is code for producer (I've reduced it for simplicity as in this case it doesn't change the problem)
from kafka import KafkaProducer
class Producer(threading.Thread):
...
def run(self):
producer = KafkaProducer(bootstrap_servers='XXX.XXX.XXX.XXX:9092')
while not self.stop_event.is_set():
string = 'test %s' %time.time()
producer.send('simulation', string.encode())
time.sleep(0.5)
producer.close()
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group my-group
– Kuhnsself.stop_event.is_set()
? Please show a minimal reproducible example – Richardsongroups.sh --describe
should not happend. Retry with a different topic and group_id. Also simplify your consumer testcase to use it without thewhile not...
part. – Continuo