question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple consumers with same group id get same message

See original GitHub issue

Kafka 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:closed
  • Created 10 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
sadaf2605commented, Sep 19, 2017
pip3 freeze | grep kafka
kafka==1.3.4.1

All my consumer with same group are getting all the same messages from all the producers.

0reactions
dpkpcommented, Dec 17, 2015

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found