@@ -338,7 +338,19 @@ def get_message(self, block=True, timeout=0.1):
338
338
with FetchContext (self , block , timeout ):
339
339
self ._fetch ()
340
340
try :
341
- return self .queue .get_nowait ()
341
+ partition , message = self .queue .get_nowait ()
342
+
343
+ # Update partition offset
344
+ self .offsets [partition ] = message .offset + 1
345
+
346
+ # Count, check and commit messages if necessary
347
+ self .count_since_commit += 1
348
+ self ._auto_commit ()
349
+
350
+ if self .partition_info :
351
+ return partition , message
352
+ else :
353
+ return message
342
354
except Empty :
343
355
return None
344
356
@@ -380,18 +392,8 @@ def _fetch(self):
380
392
partition = resp .partition
381
393
try :
382
394
for message in resp .messages :
383
- # Update partition offset
384
- self .offsets [partition ] = message .offset + 1
385
-
386
- # Count, check and commit messages if necessary
387
- self .count_since_commit += 1
388
- self ._auto_commit ()
389
-
390
395
# Put the message in our queue
391
- if self .partition_info :
392
- self .queue .put ((partition , message ))
393
- else :
394
- self .queue .put (message )
396
+ self .queue .put ((partition , message ))
395
397
except ConsumerFetchSizeTooSmall , e :
396
398
if (self .max_buffer_size is not None and
397
399
self .buffer_size == self .max_buffer_size ):
@@ -577,12 +579,11 @@ def __iter__(self):
577
579
break
578
580
579
581
# Count, check and commit messages if necessary
580
- self .offsets [partition ] = message .offset
582
+ self .offsets [partition ] = message .offset + 1
581
583
self .start .clear ()
582
- yield message
583
-
584
584
self .count_since_commit += 1
585
585
self ._auto_commit ()
586
+ yield message
586
587
587
588
self .start .clear ()
588
589
@@ -624,7 +625,7 @@ def get_messages(self, count=1, block=True, timeout=10):
624
625
messages .append (message )
625
626
626
627
# Count, check and commit messages if necessary
627
- self .offsets [partition ] = message .offset
628
+ self .offsets [partition ] = message .offset + 1
628
629
self .count_since_commit += 1
629
630
self ._auto_commit ()
630
631
count -= 1
0 commit comments