1、完整报错
Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Node may not be available. (org.apache.kafka.clients.NetworkClient)
2、背景
之前一直是直接使用项目上的Kafka,这次打算正式学习一下,所以在本地安装了Kafka,按照教程创建topic时出问题
3、操作步骤和尝试方式
1)修改Kafka配置文件
每个人的路径不完全相同,我是在
/opt/homebrew/etc/kafka/server.properties
增加了
listeners=PLAINTEXT://localhost:9092
改了好几种形式发现还是不行
2)考虑查看zookeeper是否有问题
使用命令 brew services list 查看
发现
使用./zkServer start启动,发现是找不到zoo.cfg,我的这个配置文件是在/opt/homebrew/etc/zookeeper,将文件复制到/opt/homebrew/Cellar/zookeeper/3.9.3/libexec/etc/zookeeper,重新启动就好了
3)使用lsof -i:9092查看也有内容了
4、创建topic测试
1)创建命令:
kafka-topics --create --topic test --partitions 1 --replication-factor 1 --bootstrap-server localhost:9092
2)查看主题:
kafka-topics --list --bootstrap-server localhost:9092
3)新建一个终端,启动消费者:
kafka-console-consumer --bootstrap-server localhost:9092 --topic test --from-beginning
4)新建一个终端,启动生产者
kafka-console-producer --bootstrap-server localhost:9092 --topic test
在生产者输入信息发送,消费者可以收到
5)删除topic:
kafka-topics --delete --topic test --bootstrap-server localhost:9092
5、参考文章