DevOps | Cloud | Analytics | Open Source | Programming





How To Fix - Error When Sending Message To Topic In Kafka ?



In this post , we will see How To Fix - Error When Sending Message To Topic In Kafka. Sometimes while Producing messages to a Kafka Topic , we get error messages in the Console.


$ bin/kafka-console-producer.sh --broker-list localhost:9092 --topic TEST\_TOPIC


ERROR Error when sending message to topic TEST\_TOPIC

Please note that Generally the issue occurs due to LISTENER detail conflicts. Kafka broker internally uses listeners=PLAINTEXT://HOST_IP:9092 while staring a producer. So this property must be used when you start a producer from any of the nodes. Now to fix the issue , try the below steps -  

  • Check the Topic details using Kafka topic script . The command is given below -

$ bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic TEST\_TOPIC
Topic: TEST\_TOPIC PartitionCount:1 ReplicationFactor:1 Configs:
Topic: TEST\_TOPIC Partition: 0 Leader: 2 Replicas: 2 Isr: 2

 

  • Inspect the Hostname details are Correctly given in the server.properties file . It would be similar to as shown below -

listeners=PLAINTEXT://hostname:9092

  • If Hostname details are Correct but still you are getting the Kafka Error , then Replace the Hostname with the Ip Address in the server.properties file . You need to do certain steps for that . Those are given below  -

\# Stop the Kafka Server
bin/kafka-server-stop.sh

# In Server.properties file , make changes
listeners=PLAINTEXT://0.0.0.0:9092   ---> Hostame is replace by IP Address
advertised.listeners=PLAINTEXT://HOST\_IP\_Address:9092  

# Restart the Server 
/bin/kafka-server-start.sh $KAFKA\_HOME/config/server.properties

Also ensure your Broker Port number is correct . Some installations might use different Ports. Hope this resolves the issue.   Additional Read -