Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error creating Kafka topic :- replication factor larger than available brokers

I am trying to create a kafka topic via AdminCommand using below code Source

 ZkClient zkClient = new ZkClient(kafkaHost, 10000, 10000, ZKStringSerializer$.MODULE$);
    AdminUtils.createTopic(zkClient, "pa_reliancepoc_telecom_usageevent", 10, 2, new Properties());

But getting the below exception

Exception in thread "main" kafka.admin.AdminOperationException: replication factor: 1 larger than available brokers: 0
at kafka.admin.AdminUtils$.assignReplicasToBrokers(AdminUtils.scala:70)
at kafka.admin.AdminUtils$.createTopic(AdminUtils.scala:155)

However, I am able to create the topic using shell command .

like image 511
Count Avatar asked Jan 23 '15 08:01

Count


People also ask

Can replication factor be greater than available brokers?

The thing is, you cannot create the Kafka topic with replication factor greater than your broker.

How do you increase the replication factor of a Kafka topic?

Increasing the replication factor can be done via the kafka-reassign-partitions tool. Specify the extra replicas in the custom reassignment json file and use it with the --execute option to increase the replication factor of the specified partitions.

What is Kafka topic replication factor?

Kafka Replication Factor refers to the multiple copies of data stored across several Kafka brokers. Setting the Kafka Replication Factor allows Kafka to provide high availability of data and prevent data loss if the broker goes down or cannot handle the request.

What will happen if while creating a new topic in a single broker cluster you provide replication factor of more than 1?

Apache Kafka Replication: What will happen if you set the replication factor as more than 1 while creating new topic in a single broker cluster? The Kafka cluster will automatically create more brokers to meet the replication factor. The topic will get created with the set replication factor.


2 Answers

In your code,

 AdminUtils.createTopic(zkClient, "pa_reliancepoc_telecom_usageevent", 10, 2, new Properties());

The fourth argument is the replication factor. So you are trying to create a topic with a name of pa_reliancepoc_telecom_usageevent with partition count of 10 and replication of 2. So two kafka brokers should be available while creating the topic. If less than two is available then you will get the following exception.

Exception in thread "main" kafka.admin.AdminOperationException: replication factor: 1 larger than available brokers: 0
at kafka.admin.AdminUtils$.assignReplicasToBrokers(AdminUtils.scala:70)
at kafka.admin.AdminUtils$.createTopic(AdminUtils.scala:155)

Make sure that you are running kafka cluster with two broker nodes and the two nodes should be alive while creating the topic.

To run kafka in cluster refer Step 6 in this link

like image 77
Jaya Ananthram Avatar answered Sep 21 '22 15:09

Jaya Ananthram


configure your local machine to have multiple brokers up and running in case you decide to keep your replication_factor > 1.

You can do that by simply having multiple copies of the server.properties file. e.g
server-1.properties & server-2.properties

You need to then specify different broker.id & port in each of those files to make them unique ..

   config/server-1.properties:
     broker.id=1
     port=9093
     log.dir=/tmp/kafka-logs-1

   config/server-2.properties:
     broker.id=2
     port=9094
     log.dir=/tmp/kafka-logs-2

And then start multiple instances with following commands

> bin/kafka-server-start.sh config/server-1.properties &
> bin/kafka-server-start.sh config/server-2.properties &

For more details check Step 6: Setting up a multi-broker cluster

like image 29
user2720864 Avatar answered Sep 22 '22 15:09

user2720864