go - Confluence kafka go 软件包与 ubuntu 22.04 兼容吗?

标签 go cgo confluent-kafka-go

我在 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 配置正确。

常见的检查内容是:

  1. 确保 cgo 已启用 (CGO_ENABLED="1"):

    $ go env CGO_ENABLED
    0
    $ go env -w CGO_ENABLED="1"
    
  2. 确保 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 - link librdkafka dynamically. A shared librdkafka 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/

相关文章:

go - CGO如何将 slice 传递给Rust

c - 如何调试用 cgo 调用的 C 代码?

go - 将 strfmon 与 cgo 一起使用

go - 无法使用segmentio的kafka-go连接到Confluence Kafka

http - 当我尝试使用 BindQuery 方法时,错误 : reflect. flag.mustBeAssignable 使用不可寻址的值

go - 如何从github获取go-socket.io并在Go中使用

pointers - 如何定义接收指针的 Go 接口(interface)方法的实现?

linux - Golang 在提示时输入 SSH Sudo 密码(或退出)