回答一下困扰了我一天半的一个问题,幸好现在解决了。
Spark Streaming 无法正常运行
出现这种问题很有可能是kafka 安装在wsl 或虚拟机里导致的,安装在win10里面可能不太会出现这种问题。
原因就是,在于wsl 里的ip 地址是会变化的,并且和win10里的ip不是一回事,由于因为win10版本问题可能无法通过localhost 或 127.0.0.1 这样默认的ip 来连接起来。
解决方法:
- 初级做法:在wsl 里面找到eth0 的ip 地址。接着在kafka 配置文件里面,换掉关于9092前的host.name ,在scala 里面 换掉bootstrap.servers的localhost。
- 高级做法:动态获取wsl 中的ip 地址。
参考链接:
- https://docs.microsoft.com/zh-cn/windows/wsl/networking
- https://blog.csdn.net/qq_35828475/article/details/111759464
- https://blog.csdn.net/DoubleRam/article/details/119874673
- https://www.zhihu.com/question/387747506