This is a small utility Java program that connects to Zookeeper to figure out the next available broker ID for Kafka. We make several assumptions:
- Zookeeper keeps the currently used IDs by Kafka in
/brokers/ids
. - Possible IDs are sequential from
start
tostart + total
. - Smallest ID available are always return first.
It replicates the algorithm described in Alex Etling's post on Scaling with Kafka.
This utility is very useful for scaling Kafka in a containerized environment.
Downloads from latest release (v1.0.1).
# wget
wget \
-q https://github.com/lxcid/kafka-nextbrokerid/releases/download/v1.0.1/nextbrokerid.jar \
-O /tmp/nextbrokerid.jar
Get next broker ID.
java -jar nextbrokerid.jar -zkc localhost:2181 --start 1 --total 100 --timeout 30000
⚠️ Care must be taken as the time between acquiring the next broker ID and assigning that broker ID to a Kafka instance is substantial. Race condition can occurs.