Error in Publishing message to Kafka topic

21,727

Solution 1

Alok, This very common issue of port and host.
Could you please confirm the HOST and PORT for Zookeeper and Kafka Broker. I'm assuming you have configured Kafka in your local so make sure you are providing proper host name.

Run bellow command to make sure the Zookeeper and Kafka Broker running on port which you have mentioned in your command :

netstat -a | grep port

Please let me know if you still face any issue.

Solution 2

The problem on my side has been solved by setting the value localhost to the following properties inside the config/server.properties file:

host.name
advertised.host.name
Share:
21,727
Alok
Author by

Alok

A professional with experience in machine learning and distributed computing

Updated on July 09, 2022

Comments

  • Alok
    Alok almost 2 years

    I am new to Kafka and try to setup enviroment for it . I am trying to run a single node Kafka but I am getting error in that.

    Following following steps on mac

    1. brew install zookeeper
    2. brew install kafka
    3. zkServer start
    4.  kafka-server-start.sh /usr/local/etc/kafka/server.properties
    5.bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
    6.bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test 
    This is a message
    

    But I am getting following error. Please let me know , if I missed anything

    [2015-10-19 15:48:46,632] WARN Error while fetching metadata [{TopicMetadata for topic test -> 
    No partition metadata for topic test due to kafka.common.LeaderNotAvailableException}] for topic [test]: class kafka.common.LeaderNotAvailableException  (kafka.producer.BrokerPartitionInfo)
    [2015-10-19 15:48:46,637] WARN Error while fetching metadata [{TopicMetadata for topic test -> 
    No partition metadata for topic test due to kafka.common.LeaderNotAvailableException}] for topic [test]: class kafka.common.LeaderNotAvailableException  (kafka.producer.BrokerPartitionInfo)
    [2015-10-19 15:48:46,638] ERROR Failed to collate messages by topic, partition due to: Failed to fetch topic metadata for topic: test (kafka.producer.async.DefaultEventHandler)
    [2015-10-19 15:48:46,746] WARN Error while fetching metadata [{TopicMetadata for topic test -> 
    No partition metadata for topic test due to kafka.common.LeaderNotAvailableException}] for topic [test]: class kafka.common.LeaderNotAvailableException  (kafka.producer.BrokerPartitionInfo)
    [2015-10-19 15:48:46,749] WARN Error while fetching metadata [{TopicMetadata for topic test -> 
    No partition metadata for topic test due to kafka.common.LeaderNotAvailableException}] for topic [test]: class kafka.common.LeaderNotAvailableException  (kafka.producer.BrokerPartitionInfo)
    [2015-10-19 15:48:46,749] ERROR Failed to collate messages by topic, partition due to: Failed to fetch topic metadata for topic: test (kafka.producer.async.DefaultEventHandler)
    [2015-10-19 15:48:46,860] WARN Error while fetching metadata [{TopicMetadata for topic test -> 
    No partition metadata for topic test due to kafka.common.LeaderNotAvailableException}] for topic [test]: class kafka.common.LeaderNotAvailableException  (kafka.producer.BrokerPartitionInfo)
    [2015-10-19 15:48:46,863] WARN Error while fetching metadata [{TopicMetadata for topic test -> 
    No partition metadata for topic test due to kafka.common.LeaderNotAvailableException}] for topic [test]: class kafka.common.LeaderNotAvailableException  (kafka.producer.BrokerPartitionInfo)
    [2015-10-19 15:48:46,863] ERROR Failed to collate messages by topic, partition due to: Failed to fetch topic metadata for topic: test (kafka.producer.async.DefaultEventHandler)
    [2015-10-19 15:48:46,973] WARN Error while fetching metadata [{TopicMetadata for topic test -> 
    No partition metadata for topic test due to kafka.common.LeaderNotAvailableException}] for topic [test]: class kafka.common.LeaderNotAvailableException  (kafka.producer.BrokerPartitionInfo)
    [2015-10-19 15:48:46,977] WARN Error while fetching metadata [{TopicMetadata for topic test -> 
    No partition metadata for topic test due to kafka.common.LeaderNotAvailableException}] for topic [test]: class kafka.common.LeaderNotAvailableException  (kafka.producer.BrokerPartitionInfo)
    [2015-10-19 15:48:46,977] ERROR Failed to collate messages by topic, partition due to: Failed to fetch topic metadata for topic: test (kafka.producer.async.DefaultEventHandler)
    [2015-10-19 15:48:47,083] WARN Error while fetching metadata [{TopicMetadata for topic test -> 
    No partition metadata for topic test due to kafka.common.LeaderNotAvailableException}] for topic [test]: class kafka.common.LeaderNotAvailableException  (kafka.producer.BrokerPartitionInfo)
    [2015-10-19 15:48:47,084] ERROR Failed to send requests for topics test with correlation ids in [0,8] (kafka.producer.async.DefaultEventHandler)
    [2015-10-19 15:48:47,086] ERROR Error in handling batch of 1 events (kafka.producer.async.ProducerSendThread)
    kafka.common.FailedToSendMessageException: Failed to send messages after 3 tries.
        at kafka.producer.async.DefaultEventHandler.handle(DefaultEventHandler.scala:90)
        at kafka.producer.async.ProducerSendThread.tryToHandle(ProducerSendThread.scala:105)
        at kafka.producer.async.ProducerSendThread$$anonfun$processEvents$3.apply(ProducerSendThread.scala:88)
        at kafka.producer.async.ProducerSendThread$$anonfun$processEvents$3.apply(ProducerSendThread.scala:68)
        at scala.collection.immutable.Stream.foreach(Stream.scala:547)
        at kafka.producer.async.ProducerSendThread.processEvents(ProducerSendThread.scala:67)
        at kafka.producer.async.ProducerSendThread.run(ProducerSendThread.scala:45)
    

    thanks

  • Alok
    Alok over 8 years
    I am starting with default configuration . I didnt change zookeeper.properties.
  • Alok
    Alok over 8 years
    Hi, Port seems correct to me. I verified in zoo.cfg and server.properties. I am using localhost in place of hostname.
  • Bector
    Bector over 8 years
    can you run command "hostname" on your CLI and verify what is the hostname for your machine.
  • mohsenmadi
    mohsenmadi almost 8 years
    Thanks, this worked for me. I will also add the need to setting advertised.port=yourPortNum, specially if running on a local machine and the brokers have different ports.
  • marengaz
    marengaz over 7 years
    these are now deprecated you can just remove them in favour of listeners or advertised.listeners