Alban Alban - 2 years ago 124
Java Question

Kafka: java client failed to send messages after x tries

I try to send messages into Kafka from a Java application.

All I can get is "Failed to send messages after 2 tries":

Exception in thread "main" kafka.common.FailedToSendMessageException: Failed to send messages after 2 tries.
at kafka.producer.async.DefaultEventHandler.handle(DefaultEventHandler.scala:90)
at kafka.producer.Producer.send(Producer.scala:77)
at kafka.javaapi.producer.Producer.send(Producer.scala:33)
at test.Main.main(

Kafka is running on a remote machine so I added to its
(let's say that Kafka server's IP address is

The running Kafka is
so I used (I guess) the appropriate Java-client version:


The Java code:

public static void main(String[] args) {
Properties properties = new Properties();
properties.put("", "");
properties.put("serializer.class", "test.StringEncoder");
properties.put("key.serializer.class", "test.StringEncoder");
properties.put("message.send.max.retries", "2");

Producer<String, String> kafkaProducer = new Producer<String, String>(new ProducerConfig(properties));

kafkaProducer.send(new KeyedMessage<String, String>(
"Yo! " + new Date().toString()


topic is already created. I am able to send messages into Kafka from the same machine that executes Java code using (and it works):

bin/ --broker-list --topic LOG

When Java code fails, nothing is logged by Kafka nor Zookeeper.

Is there a specific parameter I missed?

Answer Source

Apache kafka has a new producer client that is better:



Aparently your config is ok. Is "test.StringEncoder" your custom class? try yo use "kafka.serializer.StringEncoder" instead

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download