Kafka - Unable to send a message to a remote serve

2020-02-04 07:41发布

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.

4条回答
一夜七次
2楼-- · 2020-02-04 07:51

Tried connecting to kafka remote cluster from my local machine.

VM's had one internal (9.0.0.1) and one external IP (192.1.1.1). I could ssh only to the internal & not the external. I did these changes to my conifg/server.properties:

//set to the IP of the machine (find using ifconfig or hostname -I)

listeners=PLAINTEXT://192.1.1.1:9092

//set to the IP the consumer and producer will connect

advertised.listeners=PLAINTEXT://9.0.0.1:9092  
查看更多
混吃等死
3楼-- · 2020-02-04 07:59

in config/server.properties
I put this listeners=PLAINTEXT://[server_ip]:9092

and it worked fine.

For quick testing, don't forget to use [server_ip] in the command line of kafka-consumer. Example:

/usr/local/kafka_2.11-2.0.0/kafka-console-consumer.sh --property print.timestamp=true --bootstrap-server [server_ip]:9092 --topic [you_topic]

I hope this may help you.
Regards Ali

查看更多
够拽才男人
4楼-- · 2020-02-04 08:12

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.

查看更多
Ridiculous、
5楼-- · 2020-02-04 08:16

Worked with

from server.properties Uncomment

listeners=PLAINTEXT://:9092

And

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

Replace <HOST IP> with actual IP.

查看更多
登录 后发表回答