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?
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
- linklibrdkafka
dynamically. A sharedlibrdkafka
library must be installed manually through other means (apt-get, yum, build from source, etc).