Optionally skip auto-commit during consumer.close (#1031)

This commit is contained in:
Dana Powers
2017-03-13 16:39:23 -07:00
committed by GitHub
parent ce57dac0c6
commit 195df5fb98
2 changed files with 5 additions and 4 deletions

View File

@@ -376,13 +376,13 @@ class KafkaConsumer(six.Iterator):
"""
return self._subscription.assigned_partitions()
def close(self):
def close(self, autocommit=True):
"""Close the consumer, waiting indefinitely for any needed cleanup."""
if self._closed:
return
log.debug("Closing the KafkaConsumer.")
self._closed = True
self._coordinator.close()
self._coordinator.close(autocommit=autocommit)
self._metrics.close()
self._client.close()
try:

View File

@@ -325,9 +325,10 @@ class ConsumerCoordinator(BaseCoordinator):
time.sleep(self.config['retry_backoff_ms'] / 1000.0)
def close(self):
def close(self, autocommit=True):
try:
self._maybe_auto_commit_offsets_sync()
if autocommit:
self._maybe_auto_commit_offsets_sync()
finally:
super(ConsumerCoordinator, self).close()