@@ -235,6 +235,12 @@ def __init__(self, client, group, topic, auto_commit=True, partitions=None,
235
235
buffer_size = FETCH_BUFFER_SIZE_BYTES ,
236
236
max_buffer_size = MAX_FETCH_BUFFER_SIZE_BYTES ,
237
237
iter_timeout = None ):
238
+ super (SimpleConsumer , self ).__init__ (
239
+ client , group , topic ,
240
+ partitions = partitions ,
241
+ auto_commit = auto_commit ,
242
+ auto_commit_every_n = auto_commit_every_n ,
243
+ auto_commit_every_t = auto_commit_every_t )
238
244
239
245
if max_buffer_size is not None and buffer_size > max_buffer_size :
240
246
raise ValueError ("buffer_size (%d) is greater than "
@@ -245,17 +251,10 @@ def __init__(self, client, group, topic, auto_commit=True, partitions=None,
245
251
self .partition_info = False # Do not return partition info in msgs
246
252
self .fetch_max_wait_time = FETCH_MAX_WAIT_TIME
247
253
self .fetch_min_bytes = fetch_size_bytes
248
- self .fetch_started = defaultdict ( bool ) # defaults to false
254
+ self .fetch_offsets = self . offsets . copy ()
249
255
self .iter_timeout = iter_timeout
250
256
self .queue = Queue ()
251
257
252
- super (SimpleConsumer , self ).__init__ (
253
- client , group , topic ,
254
- partitions = partitions ,
255
- auto_commit = auto_commit ,
256
- auto_commit_every_n = auto_commit_every_n ,
257
- auto_commit_every_t = auto_commit_every_t )
258
-
259
258
def provide_partition_info (self ):
260
259
"""
261
260
Indicates that partition info must be returned by the consumer
@@ -301,6 +300,10 @@ def seek(self, offset, whence):
301
300
else :
302
301
raise ValueError ("Unexpected value for `whence`, %d" % whence )
303
302
303
+ # Reset queue and fetch offsets since they are invalid
304
+ self .fetch_offsets = self .offsets .copy ()
305
+ self .queue = Queue ()
306
+
304
307
def get_messages (self , count = 1 , block = True , timeout = 0.1 ):
305
308
"""
306
309
Fetch the specified number of messages
@@ -375,11 +378,11 @@ def __iter__(self):
375
378
def _fetch (self ):
376
379
# Create fetch request payloads for all the partitions
377
380
requests = []
378
- partitions = self .offsets .keys ()
381
+ partitions = self .fetch_offsets .keys ()
379
382
while partitions :
380
383
for partition in partitions :
381
384
requests .append (FetchRequest (self .topic , partition ,
382
- self .offsets [partition ],
385
+ self .fetch_offsets [partition ],
383
386
self .buffer_size ))
384
387
# Send request
385
388
responses = self .client .send_fetch_request (
@@ -394,6 +397,7 @@ def _fetch(self):
394
397
for message in resp .messages :
395
398
# Put the message in our queue
396
399
self .queue .put ((partition , message ))
400
+ self .fetch_offsets [partition ] = message .offset + 1
397
401
except ConsumerFetchSizeTooSmall , e :
398
402
if (self .max_buffer_size is not None and
399
403
self .buffer_size == self .max_buffer_size ):
0 commit comments