Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kafka-console-producer.sh TimeOutException

Tags:

apache-kafka

I am trying to send messages using the Kafka console producer to a Kafka broker that is running on the same machine. When I run

echo "Hello world" | ./kafka-console-producer.sh --broker-list localhost:9092 --topic test 

I receive the following error message:

[2016-06-29 15:00:44,069] ERROR Error when sending message to topic test with key: null, value: 11 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
org.apache.kafka.common.errors.TimeoutException: Batch containing 1 record(s) expired due to timeout while requesting metadata from brokers for test-0

When I check if the Kafka broker is listening on port 9092, it is there and running. How do I debug why cannot the command line producer connect to the broker? Thank you!

like image 691
Luděk Cigler Avatar asked Jun 29 '16 15:06

Luděk Cigler


People also ask

Where is Kafka console producer sh?

Run Kafka Producer Console Kafka provides the utility kafka-console-producer.sh which is located at ~/kafka-training/kafka/bin/kafka-console-producer.sh to send messages to a topic on the command line.

What is Kafka console consumer sh?

In this section, the users will learn how a consumer consumes or reads the messages from the Kafka topics. There are following steps taken by the consumer to consume the messages from the topic: Step 1: Start the zookeeper as well as the kafka server initially.


1 Answers

I experienced the same problem and it seems like Kafka wrote wrong metadata to zookeeper.

The easiest way to get pass this is to remove the znode in which brokers data is being registered. I.e if you use the defaults, the name should be '/brokers' and the command:

$ zkCli.sh
...
[zk: localhost:2181(CONNECTED) 1] rmr /brokers
like image 70
erankl Avatar answered Sep 27 '22 20:09

erankl