Reputation: 59
I am trying to write to a newly setup Kafka cluster on my local
echo "Hello, World" | ~/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic TutorialTopic > /dev/null
[2023-08-17 02:35:07,842] WARN [Producer clientId=console-producer] Got error produce response with correlation id 4 on topic-partition TutorialTopic-0, retrying (2 attempts left). Error: NOT_LEADER_OR_FOLLOWER (org.apache.kafka.clients.producer.internals.Sender)
.....
[2023-08-17 02:35:08,151] ERROR Error when sending message to topic TutorialTopic with key: null, value: 12 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
org.apache.kafka.common.errors.NotLeaderOrFollowerException: For requests intended only for the leader, this error indicates that the broker is not the current leader. For requests intended for any replica, this error indicates that the broker is not a replica of the topic partition.
....
I have changed the listeners value in the config.
$ cat /home/kafka/kafka/kafka.log | grep listeners
advertised.listeners = null
early.start.listeners = null
listeners = PLAINTEXT://localhost:9092
$ cat /home/kafka/kafka/kafka.log | grep 9092
listeners = PLAINTEXT://localhost:9092
[2023-08-17 02:34:49,791] INFO Awaiting socket connections on localhost:9092. (kafka.network.DataPlaneAcceptor)
[2023-08-17 02:34:49,974] INFO Registered broker 0 at path /brokers/ids/0 with addresses: PLAINTEXT://localhost:9092, czxid (broker epoch): 264 (kafka.zk.KafkaZkClient)
[2023-08-17 02:34:50,427] INFO [BrokerToControllerChannelManager broker=0 name=forwarding]: Recorded new controller, from now on will use broker localhost:9092 (id: 0 rack: null) (kafka.server.BrokerToControllerRequestThread)
[2023-08-17 02:34:50,434] INFO [BrokerToControllerChannelManager broker=0 name=alterPartition]: Recorded new controller, from now on will use broker localhost:9092 (id: 0 rack: null) (kafka.server.BrokerToControllerRequestThread)
[2023-08-17 02:37:37,461] WARN [SocketServer listenerType=ZK_BROKER, nodeId=0] Unexpected error from /127.0.0.1 (channelId=127.0.0.1:9092-127.0.0.1:48758-1); closing connection (org.apache.kafka.common.network.Selector)
Both ports 9092 and 2181 are accessible using telnet
$ telnet localhost 9092
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
hi
Connection closed by foreign host.
$ telnet localhost 2181
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
ruok
imokConnection closed by foreign host.
$ ~/kafka/bin/kafka-topics.sh --describe --topic TutorialTopic --bootstrap-server localhost:9092
Topic: TutorialTopic TopicId: rx7lEO7-RuOB-Uur_2lcAg PartitionCount: 1 ReplicationFactor: 1 Configs:
Topic: TutorialTopic Partition: 0 Leader: 0 Replicas: 0 Isr: 0
Upvotes: 1
Views: 3959
Reputation: 191738
You should use kafka-topics --create
before any producer action, otherwise, yes, there will (initially) be no leader for any non existing partition. The producer cli will retry until the topic is made...
You should realistically set auto.topics.create=false
in a production environment
Upvotes: 0