Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kafka - Unable to send a message to a remote server using Java

Tags:

I'm trying to create a Kafka cluster to send messages to a remote control. I have configured everything as described here. I am running this on a Linux red hat machine, and it works fine using the shell. After writing the java code as described in the quick start tutorial on my windows machine, I have received the following error:

...
DEBUG kafka.client.ClientUtils$ - Successfully fetched metadata for 1 topic(s)     Set(example)
...
ERROR kafka.producer.SyncProducer - Producer connection to cldExampleKafka.domain:80 unsuccessful 
java.nio.channels.UnresolvedAddressException
    ...
    at kafka.producer.async.ProducerSendThread.run(ProducerSendThread.scala:44)
...
WARN kafka.producer.async.DefaultEventHandler - Failed to send producer request with correlation id 2 to broker 0 with data for patitions [ati,0]
java.nio.channels.UnresolvedAddressException
...
kafka.common.FailedToSendMessageException: Failed to send message after 3 tries.

I have also tried to run the jar in a different Linux machine, and still received the same error.

Changing the address to localhost and running the java code as a jar in the machine where the kafka is installed works.

I believe it something with the configuration, but I couldn't find it.

like image 365
itaied Avatar asked Jan 26 '15 07:01

itaied


People also ask

Does Kafka communicate over HTTP?

Apache Kafka uses a custom protocol on top of TCP/IP for communication between applications and the Kafka cluster. With Kafka Bridge, clients can communicate with your Event Streams Kafka cluster over the HTTP/1.1 protocol. You can manage consumers and send and receive records over HTTP.


2 Answers

In your kafka server.properties there is a commented configuration

#advertised.host.name=<Some IP>

Uncomment this and add the IP of the Linux Machine in which kafka is running.

advertised.host.name=<Kafka Running Machine IP>

And connect from clients to <Kafka Running Machine IP> This should fix your issue.

EDIT

Optionally you can uncomment the

#advertised.port=9092

Also if you are listening on a different port than the default one.

like image 117
shazin Avatar answered Sep 28 '22 02:09

shazin


Worked with

from server.properties Uncomment

listeners=PLAINTEXT://:9092

And

advertised.listeners=PLAINTEXT://<HOST IP>:9092

Replace <HOST IP> with actual IP.

like image 27
Dhananjay Avatar answered Sep 28 '22 01:09

Dhananjay