英文:
Does Confluent kafka go package compatible with ubuntu 22.04?
问题
我正在使用confluent kafka包在我的数据流服务器中,使用的是Ubuntu 20.04和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包可以正常工作。问题是我想使用confluent包,因为它具有订阅和取消订阅功能,我认为这是相对于segmentio包的优势。
有人知道如何解决这个错误吗?
英文:
I was using confluent kafka package for my data streaming server in golang using ubuntu 20.04 and now I changed my os to ubuntu 22.04.
Now im getting these errors:
- 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
But the segmentio package is working fine in the same code. The thing is I want to use confluent package because it has subscribe and unsubscribe features, which I felt advantage over the segemntio package.
Does anyone knows how to fix this error?
答案1
得分: 2
由于github.com/confluentinc/confluent-kafka-go/v2/kafka
包使用了librdkafka
C库的绑定,您首先必须确保cgo正确配置。
常见的检查事项包括:
-
确保cgo已启用(
CGO_ENABLED="1"
):$ go env CGO_ENABLED 0 $ go env -w CGO_ENABLED="1"
-
确保C编译器可用。运行
go env CC
查看使用的C编译器。
除了检查cgo,还需要确保librdkafka
可用。请参阅构建标签:
- 默认情况下,将使用捆绑的特定平台的静态构建的
librdkafka
。这在Mac OSX和基于glibc的Linux发行版(如Ubuntu和CentOS)上可以直接使用。- 在基于musl的Linux发行版(如Alpine)上构建时,必须指定
-tags musl
。将使用捆绑的静态musl构建的librdkafka
。- 使用
-tags dynamic
动态链接librdkafka
。必须通过其他方式手动安装共享的librdkafka
库(apt-get、yum、从源代码构建等)。
英文:
Since the github.com/confluentinc/confluent-kafka-go/v2/kafka
package uses bindings on-top of the librdkafka
C library, you have to make sure cgo is configured correctly first.
The common things to check are:
-
make sure cgo is enabled (
CGO_ENABLED="1"
):$ go env CGO_ENABLED 0 $ go env -w CGO_ENABLED="1"
-
make sure the C compiler is available. run
go env CC
to see which C compiler is used.
Besides checking cgo, it's also necessary to make sure librdkafka
is available. See 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
- link librdkafka
dynamically. A shared librdkafka
library must be installed manually through other means (apt-get, yum, build from source, etc).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论