本地IDEA运行sparkStreaming消费kafka出错 Connection with localhost/127.0.0.1 disconnected

可以看到报错第一句显示:Connection with localhost/127.0.0.1 disconnected

但是我明明在application.yml中配置了我的Kafka Server的地址是:192.168.52.131:9092,而在实际连接kafka服务器时却使用的localhost/127.0.0.1这个地址,所以导致无法连接kafka Server。

 

经过百度,得知,在设置Kafka的时候,需要设置advertised.listeners这个属性。

 

该属性在config/server.properties中的描述如下:

# 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

 

翻译过来就是hostname和端口是用来建议给生产者和消费者使用的,如果没有设置,将会使用listeners的配置,如果listeners也没有配置,将使用java.net.InetAddress.getCanonicalHostName()来获取这个hostname和port,对于ipv4,基本就是localhost了。

 

"PLAINTEXT"表示协议,可选的值有PLAINTEXT和SSL,hostname可以指定IP地址,也可以用"0.0.0.0"表示对所有的网络接口有效,如果hostname为空表示只对默认的网络接口有效

也就是说如果你没有配置advertised.listeners,就使用listeners的配置通告给消息的生产者和消费者,这个过程是在生产者和消费者获取源数据(metadata)。

 

因此重新设置advertised.listeners为如下:

advertised.listeners=PLAINTEXT://192.168.52.131:9092

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章