Multiple consumers with same group id get same message
See original GitHub issueKafka manual says that each message is delivered exactly to one consumer from a group (with a same group id). And this is what I see with Java high-level API and expected to see with Python’s SimpleConsumer
. However, when I run 2 consumers simultaneously (see code below) and send new message, both instances of consumer receive it.
# consumer.py
from kafka.client import KafkaClient
from kafka.consumer import SimpleConsumer
kafka = KafkaClient("broker", 9092)
consumer = SimpleConsumer(kafka, "my-group", "my-topic",
auto_commit=False)
while True:
msg = consumer.get_message()
if msg:
print(msg)
else:
print('no new messages')
kafka.close()
# producer.py
from kafka.client import KafkaClient
from kafka.producer import SimpleProducer
kafka = KafkaClient("broker", 9092)
producer = SimpleProducer(kafka, "my-topic")
producer.send_messages("my message")
kafka.close()
Note, that auto_commit
in consumer is set to False
to overcome problem with Kafka 0.8.1 and current version of kafka-python, but changing it to True only adds exceptions and doesn’t fix consumption problem.
Issue Analytics
- State:
- Created 10 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Can multiple Kafka consumers read same message from the ...
If you have 2 Kafka consumers with the same Group Id, they will both read 6 partitions, meaning they will read different set...
Read more >Can multiple Kafka consumers read the same message from a ...
[…] A consumer can be assigned to consume multiple partitions. So the rule in Kafka is only one consumer in a consumer group...
Read more >How to parallelise Kafka consumers | by Jhansi Karee - Medium
Consumers registered with the same group-id would be part of one group. Group-id plays a crucial role in consumption from Kafka. Consumers would ......
Read more >Chapter 4. Kafka Consumers: Reading Data from Kafka
Kafka consumers are typically part of a consumer group . When multiple consumers are subscribed to a topic and belong to the same...
Read more >Kafka - Understanding Consumer Group with examples
When multiple consumers are subscribed to a topic and belong to the same consumer group, each consumer in the group will receive messages...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
All my consumer with same group are getting all the same messages from all the producers.
yes, #38 is the tracking issue. consumer rebalancing will be supported when using kafka brokers >= v0.9.0.0 . Development is on the 0.9 git branch.