初次使用spring连接kafka遇到的问题:org.apache.kafka.clients.networkclient broker may not be available

最近学习使用kafka用消息队列,在虚拟机上装了kafka,单机版,未做集群。

然后,用spring连接kafka,尝试发一条消息,刚玩起来就给报了警告,


控制台报的警告信息

2018-05-02 14:49:18.916 WARN 11916 --- [ntainer#0-3-C-1] org.apache.kafka.clients.NetworkClient : [Consumer clientId=consumer-4, groupId=cwenao-group] Connection to node 0 could not be established. Broker may not be available.

2018-05-02 14:49:20.098  WARN 11916 --- [ntainer#0-2-C-1] org.apache.kafka.clients.NetworkClient  : [Consumer clientId=consumer-3, groupId=cwenao-group] Connection to node 0 could not be established. Broker may not be available.

2018-05-02 14:49:20.104  WARN 11916 --- [ntainer#0-0-C-1] org.apache.kafka.clients.NetworkClient  : [Consumer clientId=consumer-1, groupId=cwenao-group] Connection to node 0 could not be established. Broker may not be available.

2018-05-02 14:49:20.146  WARN 11916 --- [ntainer#0-1-C-1] org.apache.kafka.clients.NetworkClient  : [Consumer clientId=consumer-2, groupId=cwenao-group] Connection to node 0 could not be established. Broker may not be available.

2018-05-02 14:49:20.375  WARN 11916 --- [ntainer#0-3-C-1] org.apache.kafka.clients.NetworkClient  : [Consumer clientId=consumer-4, groupId=cwenao-group] Connection to node 0 could not be established. Broker may not be available.

类似这样的信息是不断的报,不断的报,已经很明显,消息是发不成功的了。

在网上找了下,有童鞋说,可能是kafka配置没配好,kafka配置没有对外开放host、port


网上童鞋说的

原文链接:https://www.jianshu.com/p/ed9055bc68a6

好吧,我尝试一下看看,


原来的配置



修改后的配置

我已经把advertised.listeners配上了,配好后,把kafka重启,再跑spring应用。

这下好了,没有那个警告了,消息也正常发送成功了。


消息发送成功


好了,希望能帮助到同样是刚开始学习kafka的你^_^

你可能感兴趣的:(初次使用spring连接kafka遇到的问题:org.apache.kafka.clients.networkclient broker may not be available)