Skip to content

docs: add manual offset commit example#3015

Open
vividbaek wants to merge 1 commit into
dpkp:masterfrom
vividbaek:docs/add-manual-offset-commit-example
Open

docs: add manual offset commit example#3015
vividbaek wants to merge 1 commit into
dpkp:masterfrom
vividbaek:docs/add-manual-offset-commit-example

Conversation

@vividbaek
Copy link
Copy Markdown

Add a short KafkaConsumer example showing manual offset commits with TopicPartition and OffsetAndMetadata. Clarifies that you should commit the next offset to consume (e.g. commit message.offset + 1).

Quick example:

from kafka import KafkaConsumer, OffsetAndMetadata, TopicPartition
consumer = KafkaConsumer('my-topic', group_id='g', enable_auto_commit=False)
for msg in consumer:
process_message(msg)
tp = TopicPartition(msg.topic, msg.partition)
consumer.commit({tp: OffsetAndMetadata(msg.offset + 1, '', -1)})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant