Skip to content

Commit 0dbcb6e

Browse files
committed
Retry Client#partitions_for up to two times
1 parent 6579253 commit 0dbcb6e

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/kafka/client.rb

+16-1
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,22 @@ def has_topic?(topic)
700700
# @param topic [String]
701701
# @return [Integer] the number of partitions in the topic.
702702
def partitions_for(topic)
703-
@cluster.partitions_for(topic).count
703+
attempt = 1
704+
705+
begin
706+
@cluster.partitions_for(topic).count
707+
rescue LeaderNotAvailable
708+
if attempt >= 3
709+
raise
710+
else
711+
attempt += 1
712+
@logger.warn "Leader not available, retrying in 1s..."
713+
714+
sleep 1
715+
716+
retry
717+
end
718+
end
704719
end
705720

706721
# Counts the number of replicas for a topic's partition

0 commit comments

Comments
 (0)