Java客户端连接kafka集群报错

往kafka集群发送消息时,报错如下:

page_visits-1: 30005 ms has passed since batch creation plus linger time

加入log4j.properties,设置为DEBUG级别,错误如下:

2017-06-03 17:33:31,417 DEBUG [org.apache.kafka.clients.NetworkClient] - Error connecting to node 2 at kafka-cluster-64bit:9094:
java.io.IOException: Can't resolve address: kafka-cluster-64bit:9094
    at org.apache.kafka.common.network.Selector.connect(Selector.java:182)
    at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:629)
    at org.apache.kafka.clients.NetworkClient.ready(NetworkClient.java:186)
    at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:184)
    at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:126)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.nio.channels.UnresolvedAddressException
    at sun.nio.ch.Net.checkAddress(Net.java:101)
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:622)
    at org.apache.kafka.common.network.Selector.connect(Selector.java:179)
    ... 5 more

 

解决办法:

config/server.properties修改

修改前:listeners=PLAINTEXT://:9092

修改后:listeners=PLAINTEXT://192.168.137.176:9092

具体代码参照:Kafka JAVA客户端代码示例

posted @ 2017-06-03 18:05  静候东风  阅读(3367)  评论(0编辑  收藏  举报