Kafka - 无法使用Java向远程服务器发送消息 [英] Kafka - Unable to send a message to a remote server using Java

查看:1467
本文介绍了Kafka - 无法使用Java向远程服务器发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个 Kafka 群集来向远程控制发送消息。我按照此处所述配置了所有内容。
我在 Linux red hat 机器上运行它,并且使用shell工作正常。在我的Windows机器上按照快速入门教程中的描述编写java代码后,我收到以下错误:

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.

我还尝试在不同的Linux机器上运行jar,但仍然收到同样的错误。

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

将地址更改为 localhost 并在安装kafka的机器中将jar代码作为jar运行。

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.

推荐答案

在你的kafka server.properties 中有一个注释配置

In your kafka server.properties there is a commented configuration

#advertised.host.name=<Some IP>

取消注释并添加运行kafka的Linux机器的IP。

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

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

从客户端连接到< Kafka Running Machine IP> 这应该可以解决您的问题。

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

编辑

您可以选择可以取消注释

Optionally you can uncomment the

#advertised.port=9092

此外,如果您正在侦听与默认端口不同的端口。

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

这篇关于Kafka - 无法使用Java向远程服务器发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆