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.

consumer manual commit not working

See original GitHub issue

Hi, when I run my consumer script I disable auto commits because in my use case there are some messages that need to be processed and if we got no errors then we can remove them from the queue hence the manual commit bit.

But when I manually commit the offset it is still there on next iteration of my script; of course if I re-enable auto-commit it’s gone…

this is my code:

from kafka import KafkaConsumer
from kafka.structs import OffsetAndMetadata

consumer = KafkaConsumer(bootstrap_servers='192.168.33.10:9092', consumer_timeout_ms=1000, enable_auto_commit=False)
consumer.subscribe(['my-topic', 'another-topic'])

for message in consumer:
    print (message)
    meta = consumer.partitions_for_topic(message.topic)
    partition = consumer.assignment().pop()
    offsets = OffsetAndMetadata(message.offset, meta)
    options = {partition: offsets}
    consumer.commit(offsets=options)
consumer.close()

any hints?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tkaymakcommented, Apr 17, 2018

Is this still the right way to do manual commits?

1reaction
dpkpcommented, Aug 23, 2016

assignment().pop() is wrong. That could give you any partition, but you want the particular messag e partition. Use TopicPartition(message.topic, message.partition)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Manual Commit Not Working As Expected · Issue #527 - GitHub
Let's say if my consumer (the only one in the consumer group) is currently consuming a message at offset 7, then some error...
Read more >
Kafka manual commit problem : r/apachekafka - Reddit
Commit is a synchronous call but returns no errors. So we are not really sure at present why the commit does not take...
Read more >
Spring kafka manual offset commit does not work as expected
When I forcefully crash (JVM) consumer application and start it again, the consumer does not fetch records from the last committed offset.
Read more >
Apache Kafka Offset Management - Learning Journal
The solution to this particular problem is a manual commit. So, we can configure the auto-commit off and manually commit after processing the...
Read more >
Consuming Messages - KafkaJS
When suppling a regular expression, the consumer will not match topics created ... When disabling autoCommit you can still manually commit message offsets, ......
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