Kafka Broker may not be available on 127.0.0.1:2181

Viewed 8311

I'm trying to run a kafka cluster with this command :

kafka-topics.sh --bootstrap-server 127.0.0.1:2181 --topic first_topic --create --partitions 3 --replication-factor 1

and i get this as an error:

[2022-02-03 11:25:28,635] WARN [AdminClient clientId=adminclient-1] Connection to node -1 (/127.0.0.1:2181) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

So i tried to look at kafka_2.12-3.1.0\config\server.properties i have

listeners=PLAINTEXT://localhost:9092

Any help will be very appreciated.

1 Answers

2181 is typically the port used by ZooKeeper. If you want to specify that, and you're not running Kafka in KRaft (zookeeper-less mode) then you need to do as @Umeshwaran said and use the --zookeeper argument.

However, you can use --bootstrap-server, but if you are doing so then specify the broker address and port, which from your listeners config is 9092:

kafka-topics.sh --bootstrap-server 127.0.0.1:9092 --topic first_topic --create --partitions 3 --replication-factor 1

This article should clarify things.

Related