Skip to content

Commit 1d252bf

Browse files
author
Dana Powers
committed
Bulk fetch offset partitions in base consumer -- suggested by ecanzonieri
1 parent b6d032c commit 1d252bf

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

kafka/consumer/base.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,13 @@ def fetch_last_known_offsets(self, partitions=None):
8383
if not partitions:
8484
partitions = self.client.get_partition_ids_for_topic(self.topic)
8585

86-
for partition in partitions:
87-
(resp,) = self.client.send_offset_fetch_request(
88-
self.group,
89-
[OffsetFetchRequest(self.topic, partition)],
90-
fail_on_error=False
91-
)
86+
responses = self.client.send_offset_fetch_request(
87+
self.group,
88+
[OffsetFetchRequest(self.topic, p) for p in partitions],
89+
fail_on_error=False
90+
)
91+
92+
for resp in responses:
9293
try:
9394
check_error(resp)
9495
# API spec says server wont set an error here
@@ -98,12 +99,12 @@ def fetch_last_known_offsets(self, partitions=None):
9899

99100
# -1 offset signals no commit is currently stored
100101
if resp.offset == -1:
101-
self.offsets[partition] = 0
102+
self.offsets[resp.partition] = 0
102103

103104
# Otherwise we committed the stored offset
104105
# and need to fetch the next one
105106
else:
106-
self.offsets[partition] = resp.offset
107+
self.offsets[resp.partition] = resp.offset
107108

108109
def commit(self, partitions=None):
109110
"""

0 commit comments

Comments
 (0)