问题描述
- 当 golang 使用 github.com/Shopify/sarama 调用 kafka 时会遇到下面两个问题
- go mod tidy 事后会遇到路径错误
- 编译后连接 kafka 也会有错误信息
go mod tidy 错误信息
go: github.com/IBM/sarama@v1.43.3 used for two different module paths (github.com/IBM/sarama and github.com/Shopify/sarama)
-
因为 IBM 收购了项目, 因此项目代码已经完全迁移至 IBM 组织中
-
解决方法 修改 go.mod 文件, 通过 replace 指定一个版本
replace github.com/Shopify/sarama => github.com/IBM/sarama v1.43.3
新版本 sarama 启动会遇到下面错误
[2024-12-03 16:33:11.447] [INFO] [37888] [commands.go:33] >>> [falcon-kafka_consumer] msg=proc.Start, ok
[2024-12-03 16:33:11.448] [INFO] [37888] [commands.go:33] >>> [falcon-kafka_consumer] msg=send.Start, ok
[2024-12-03 16:33:11.448] [INFO] [37888] [commands.go:33] >>> [falcon-kafka_consumer] msg=start to init consumer group of low version kafka
[2024-12-03 16:33:11.448] [INFO] [37888] [commands.go:33] >>> [falcon-kafka_consumer] msg=http.startHttpServer ok, listening: 0.0.0.0:6850
[2024-12-03 16:33:12.241] [ERROR] [37888] [commands.go:33] >>> [falcon-kafka_consumer] msg=init high consumer group error: kafka: client has run out of available brokers to talk to: 6 errors occurred:
* EOF
* EOF
* EOF
* EOF
-
参考官网, 降版本后可解决问题
-
修改 go.mod 文件如下
replace github.com/Shopify/sarama => github.com/IBM/sarama v0.0.0-20180712172306-5cd4d8675b3b
replace github.com/IBM/sarama => github.com/Shopify/sarama v0.0.0-20180712172306-5cd4d8675b3b