Fork me on Gitee

kafka调试中遇到could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)


启动生产者命令:

kafka-console-producer.bat --broker-list localhost:9092 --topic haha


启动消费者:

kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic haha --from-beginning

kafka 配置文件:

############################# Socket Server Settings #############################

# The address the socket server listens on. It will get the value returned from 
# java.net.InetAddress.getCanonicalHostName() if not configured.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
# 允许外部端口连接   
listeners=PLAINTEXT://localhost:9092

# Hostname and port the broker will advertise to producers and consumers. If not set, 
# it uses the value for "listeners" if configured.  Otherwise, it will use the value
# returned from java.net.InetAddress.getCanonicalHostName().
#advertised.listeners=PLAINTEXT://your.host.name:9092
                                         
# 外部代理地址                                                
advertised.listeners=PLAINTEXT://localhost:9092
# Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details
#listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL

解决办法:

消费者代码:

kafka-console-consumer.bat --bootstrap-server PLAINTEXT://localhost:9092 --topic haha --from-beginning

疑问:?

这里比较奇怪; 生产者没有加PLAINTEXT:// 能够正常启动 在消费者居然能够报错? 诡异

kafka 版本:"

kafka_2.13-2.4.0\kafka-logs"

posted @ 2020-02-21 22:09  ---dgw博客  阅读(11909)  评论(0编辑  收藏  举报