Skip to content

Commit f7d6fdd

Browse files
authored
Fix consumer example (confluentinc#1463)
* Fix consumer example - Use store_offset for atleast once semantics. * Address comments
1 parent 395f939 commit f7d6fdd

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

examples/consumer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def print_usage_and_exit(program_name):
5252
# Consumer configuration
5353
# See https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md
5454
conf = {'bootstrap.servers': broker, 'group.id': group, 'session.timeout.ms': 6000,
55-
'auto.offset.reset': 'earliest'}
55+
'auto.offset.reset': 'earliest', 'enable.auto.offset.store': False}
5656

5757
# Check to see if -T option exists
5858
for opt in optlist:
@@ -102,6 +102,10 @@ def print_assignment(consumer, partitions):
102102
(msg.topic(), msg.partition(), msg.offset(),
103103
str(msg.key())))
104104
print(msg.value())
105+
# Store the offset associated with msg to a local cache.
106+
# Stored offsets are committed to Kafka by a background thread every 'auto.commit.interval.ms'.
107+
# Explicitly storing offsets after processing gives at-least once semantics.
108+
c.store_offsets(msg)
105109

106110
except KeyboardInterrupt:
107111
sys.stderr.write('%% Aborted by user\n')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy