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 -
$ 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
listeners=PLAINTEXT://hostname:9092
\# 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 -