Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR Error when sending message to topic

Tags:

apache-kafka

Instead of changing server.properties include the address 0.0.0.0 in the code itself. Instead of

/usr/bin/kafka-console-producer --broker-list Hostname:9092 --topic MyFirstTopic1

use

/usr/bin/kafka-console-producer --broker-list 0.0.0.0:9092 --topic MyFirstTopic1

It may be because of some parameters from Kafka's server.properties file. You can find more information here

  1. Stop the Kafka server with

    cd $KAFKA_HOME/bin  
    ./kafka-server-stop.sh
    
  2. Change

    listeners=PLAINTEXT://hostname:9092   
    

    to

    listeners=PLAINTEXT://0.0.0.0:9092

    in $KAFKA_HOME/config/server.properties

  3. Restart the Kafka server with

    $KAFKA_HOME/bin/kafka-server-start.sh $KAFKA_HOME/config/server.properties  
    

I know this is old but this may work for someone else who's dealing with it: I changed 2 things:
1. change the "bootstrap.servers" property or the --broker-list option to 0.0.0.0:9092
2. change (uncomment and edit in my case) the server.properties in 2 properties

  • listeners = PLAINTEXT://your.host.name:9092 to listeners=PLAINTEXT://:9092
  • advertised.listeners=PLAINTEXT://your.host.name:9092 to advertised.listeners=PLAINTEXT://localhost:9092

If you are running hortonworks cluster, check the listening port in ambari.

In my case 9092 was not my port. I went to ambari and found the listening port was set to 6667 it worked for me. :)


I faced similar problem, where I was able to produce and consume on localhost but not from different machines on network. Based few answers I got the clue that essentially we need to expose advertised.listener to producer and consumer, however giving 0.0.0.0 was also not working. So gave exact IP against advertised.listeners

advertised.listeners=PLAINTEXT://HOST.IP:9092

And I left listener=PLAINTEXT://:9092 as it is.

So with this the spark exposes advertised ip and port to producers and consumers


I get the same error today with confluent_kafka 0.9.2 (0x90200) and librdkafka 0.9.2 (0x90401). In my case, I specified the wrong broker port in tutorialpoints example:

$ kafka-console-producer.sh --broker-list localhost:9092 --topic tutorialpoint-basic-ops-01

although my broker was started on port 9094:

$ cat server-02.properties 
broker.id=2
port=9094
log.dirs=/tmp/kafka-example-logs-02
zookeeper.connect=localhost:2181

Although the 9092 port was not open (netstat -tunap), it took 60s for kafka-console-producer.sh to raise an error. Looks like this tool needs a fix to:

  • fail faster
  • with a more explicit error message.

I faced the above exception stacktrace. I investigated and found the root cause.I faced it when I established Kafka cluster with two nodes.With the following settings in server.properties.Here I am denoting server.properties of kafka node 1 and 2 as broker1.properties and broker2.properties

broker1.properties settings

    listeners=PLAINTEXT://A.B.C.D:9092
    zookeeper.connect=A.B.C.D:2181,E.F.G.H:2181

broker2.properties settings

    listeners=PLAINTEXT://E.F.G.H:9092
    zookeeper.connect=A.B.C.D:2181,E.F.G.H:2181

I was trying to start a producer from node1 or from node2 using the following command: ./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic OUR_TOPIC and I was getting the above timeout exception stacktrace although Kafka is running in both machine.

Although producer is starting either from Leader node or from a follower I was always getting the same.

While using below command from any broker I was able to get producer the message.

   ./bin/kafka-console-producer.sh --broker-list A.B.C.D:9092 --topic OUR_TOPIC
    or
   ./bin/kafka-console-producer.sh --broker-list E.F.G.H:9092 --topic OUR_TOPIC
   or
   ./bin/kafka-console-producer.sh --broker-list A.B.C.D:9092,E.F.G.H:9092 --topic OUR_TOPIC

So the root cause is that Kafka broker internally using listeners=PLAINTEXT://E.F.G.H:9092 property while staring a producer.This property must match to start a kafka broker from any of the node while starting a producer.Converting this property to listeners=PLAINTEXT://localhost:9092 will work for our very first command.