释放双眼,带上耳机,听听看~!
🤖 由 ChatGPT 生成的文章摘要
具体报错如下
[2023-08-29 06:25:19,540] ERROR [Producer clientId=console-producer] Uncaught error in kafka producer I/O thread: (org.apache.kafka.clients.producer.internals.Sender)
java.lang.IllegalStateException: No entry found for connection 0
at org.apache.kafka.clients.ClusterConnectionStates.nodeState(ClusterConnectionStates.java:339)
at org.apache.kafka.clients.ClusterConnectionStates.disconnected(ClusterConnectionStates.java:143)
at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:921)
at org.apache.kafka.clients.NetworkClient.access$700(NetworkClient.java:67)
at org.apache.kafka.clients.NetworkClient$DefaultMetadataUpdater.maybeUpdate(NetworkClient.java:1086)
at org.apache.kafka.clients.NetworkClient$DefaultMetadataUpdater.maybeUpdate(NetworkClient.java:971)
at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:533)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:311)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:235)
at java.lang.Thread.run(Thread.java:748)
[2023-08-29 06:25:19,554] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 18 : {one=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
[2023-08-29 06:25:19,655] ERROR [Producer clientId=console-producer] Uncaught error in kafka producer I/O thread: (org.apache.kafka.clients.producer.internals.Sender)
java.lang.IllegalStateException: No entry found for connection 0
at org.apache.kafka.clients.ClusterConnectionStates.nodeState(ClusterConnectionStates.java:339)
at org.apache.kafka.clients.ClusterConnectionStates.disconnected(ClusterConnectionStates.java:143)
at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:921)
at org.apache.kafka.clients.NetworkClient.access$700(NetworkClient.java:67)
at org.apache.kafka.clients.NetworkClient$DefaultMetadataUpdater.maybeUpdate(NetworkClient.java:1086)
at org.apache.kafka.clients.NetworkClient$DefaultMetadataUpdater.maybeUpdate(NetworkClient.java:971)
at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:533)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:311)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:235)
at java.lang.Thread.run(Thread.java:748)
解决办法:
问题原因:客户端在连接kafka集群时不能解析出kafka机器的hostname对应的ip值
在客户端的机器上添加kafka集群的Host。
原配置文件
root@abcdocker:~# cat /usr/local/kafka/config/server.properties
broker.id=1
listeners=PLAINTEXT://:9092
...
添加host解析
cat >>/etc/hosts<<EOF
192.168.31.70 kafka1
192.168.31.71 kafka2
192.168.31.72 kafka3
EOF
修改后
[root@tmp-01 kafka]# cat config/server.properties
broker.id=0
listeners=PLAINTEXT://kafka1:9092
测试生产消费
- 执行生产者命令
[root@tmp-01 kafka]# /usr/local/kafka/bin/kafka-console-producer.sh --broker-list 192.168.31.70:9092 --topic one
>I am abcdocker
>site:i4t.com
>mail: 1272204@qq.com
>END!
- 执行消费者命令
[root@tmp-01 kafka]# /usr/local/kafka/bin/kafka-console-consumer.sh --bootstrap-server 192.168.31.70:9092 --from-beginning --topic one
I am abcdocker
site:i4t.com
END!