SpringBoot连接kafka报Connection to node 0 (/10.0.24.17:9092) could not be established. Broker may not be

smile-hu 发表于: 2021-12-13   最后更新时间: 2021-12-13 17:22:56   4,656 游览

kafka是在腾讯云服务器上安装的,我配置完之后,通过外网ip可以ping通,但是用程序连接,报这个警告:

Connection to node 0 (/10.0.24.17:9092) could not be established. Broker may not be
available.

kafka配置

# broker的编号,如果集群中有多个broker,则每个broker的编号需要不同
broker.id=0
# 对外提供的服务入口地址
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://10.0.24.17:9092
# 存放消息日志文件的地址  记得创建日志文件夹
log.dirs=/data/kafka/log
# zookeeper配置,如果是集群的话,用“,”隔开 127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002
zookeeper.connect=localhost:2181

地址

  • 内网ip:10.0.24.17
  • 外网ip:82.157.172.60

客户端错误

客户端springboot连接的是kafka的外网地址:82.157.172.60:9092

运行连接时报错,如下:

[Producer clientId=producer-1] Connection to node 0 (/10.0.24.17:9092) could not be established. Broker may not be available.
[Consumer clientId=consumer-zhTestGroup-1, groupId=zhTestGroup] Connection to node 0 (/10.0.24.17:9092) could not be established. Broker may not be available.
[Producer clientId=producer-1] Connection to node 0 (/10.0.24.17:9092) could not be established. Broker may not be available.
[Consumer clientId=consumer-zhTestGroup-1, groupId=zhTestGroup] Connection to node 0 (/10.0.24.17:9092) could not be established. Broker may not be available.
[Producer clientId=producer-1] Connection to node 0 (/10.0.24.17:9092) could not be established. Broker may not be available.
[Consumer clientId=consumer-zhTestGroup-1, groupId=zhTestGroup] Connection to node 0 (/10.0.24.17:9092) could not be established. Broker may not be available.
发表于 2021-12-13
¥1.0

将配置改为:

# 监听列表,用于kafka对内和对外
listeners=PLAINTEXT://10.0.24.17:9092
# 供客户端使用的监听地址,所以配置外网端口(对外)
advertised.listeners=PLAINTEXT://82.157.172.60:9092

参考来自:Kafka Broker配置

你的答案

查看kafka相关的其他问题或提一个您自己的问题