Nick's Blog

Error while executing topic command : Replication factor: 2 larger than available brokers: 1

When you working with kafka-topics CLI to create topic, you may experience the following error:

Error while executing topic command : Replication factor: 2 larger than available brokers: 1.
[2019-11-25 22:10:12,060] ERROR org.apache.kafka.common.errors.InvalidReplicationFactorException: Replication factor: 2 larger than available brokers: 1.
 (kafka.admin.TopicCommand$)

Let’s take a look the command I was running.

kafka-topics --zookeeper 127.0.0.1:2181 --topic first_topic --create --partitions 3 --replication-factor 2

You have noticed that I have a –replication-factor parameter set up with a value 2.

Let’s run another command to see how many broker node do we have.

zookeeper-shell localhost:2181 ls /brokers/ids

I get a result of [0] which means I only have 1 broker. However, the previous command I was running have a 2 replication factor defined.

The value is greater than the number of broker, therefore, I got the error. If I reduce the replication-factor down to 1. The error disappeared.

kafka-topics --zookeeper 127.0.0.1:2181 --topic first_topic --create --partitions 3 --replication-factor 1