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/ --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/ --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 file . It would be similar to as shown below -


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

\# Stop the Kafka Server

# In file , make changes
listeners=PLAINTEXT://   ---> Hostame is replace by IP Address

# Restart the Server 
/bin/ $KAFKA\_HOME/config/

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