我在 ubuntu 20.04 中使用 confluence kafka 包作为 golang 中的数据流服务器,现在我将操作系统更改为 ubuntu 22.04。
现在我收到这些错误:
- kafka.producer/producer.go:18:26: undefined: kafka.Producer
- kafka.producer/producer.go:35:17: undefined: kafka.ConfigMap
- kafka.producer/producer.go:40:30: undefined: kafka.NewProducer
- kafka.producer/producer.go:133:50: undefined: kafka.Message
- kafka.producer/producer.go:134:27: undefined: kafka.TopicPartition
- kafka.producer/producer.go:136:23: undefined: kafka.PartitionAny
但是segmentio包在相同的代码中运行良好。问题是我想使用 confluence 包,因为它具有订阅和取消订阅功能,我觉得它比 segemntio 包更有优势。
有人知道如何解决这个错误吗?
最佳答案
由于 github.com/confluenceinc/confluence-kafka-go/v2/kafka
包使用 librdkafka
C 库顶部的绑定(bind),因此您必须首先确保 cgo 配置正确。
常见的检查内容是:
确保 cgo 已启用 (
CGO_ENABLED="1"
):$ go env CGO_ENABLED 0 $ go env -w CGO_ENABLED="1"
确保 C 编译器可用。运行
go env CC
查看使用的是哪个 C 编译器。
除了检查 cgo 之外,还需要确保 librdkafka
可用。请参阅build tags :
- By default the bundled platform-specific static build of librdkafka will be used. This works out of the box on Mac OSX and glibc-based Linux distros, such as Ubuntu and CentOS.
-tags musl
- must be specified when building on/for musl-based Linux distros, such as Alpine. Will use the bundled static musl build of librdkafka.-tags dynamic
- linklibrdkafka
dynamically. A sharedlibrdkafka
library must be installed manually through other means (apt-get, yum, build from source, etc).
关于go - Confluence kafka go 软件包与 ubuntu 22.04 兼容吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76239071/