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

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

问题描述

我正在尝试创建一个 Kafka 集群来向遥控器发送消息.我已经按照此处的描述配置了所有内容.我在 Linux red hat 机器上运行它,它使用 shell 运行良好.在我的 Windows 机器上按照 quick start 教程中所述编写 java 代码后,我收到以下错误:

<预><代码>...DEBUG kafka.client.ClientUtils$ - 成功获取 1 个主题的元数据集(示例)...错误 kafka.producer.SyncProducer - 生产者连接到 cldExampleKafka.domain:80 不成功java.nio.channels.UnresolvedAddressException...在 kafka.producer.async.ProducerSendThread.run(ProducerSendThread.scala:44)...警告 kafka.producer.async.DefaultEventHandler - 无法将具有相关性 id 2 的生产者请求发送到代理 0 以及 patitions [ati,0] 的数据java.nio.channels.UnresolvedAddressException...kafka.common.FailedToSendMessageException:尝试 3 次后无法发送消息.

我也尝试在不同的 Linux 机器上运行 jar,但仍然收到相同的错误.

将地址更改为 localhost 并将 java 代码作为 jar 在安装了 kafka 的机器上运行.

我相信它与配置有关,但我找不到.

解决方案

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

#advertised.host.name=<某些 IP>

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

advertised.host.name=

并从客户端连接到 这应该可以解决您的问题.

编辑

或者,您可以取消注释

#advertised.port=9092

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

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.

解决方案

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.

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

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