在 Linux 上使用 confluent-kafka-go 构建 Go 应用程序 [英] Building Go Application using confluent-kafka-go on Linux

查看:40
本文介绍了在 Linux 上使用 confluent-kafka-go 构建 Go 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用我的 go 应用程序创建一个 docker 映像.该应用程序(在 MacOS 上开发)依赖于 confluent-kafka-go,而后者又依赖于我安装在 Docker 镜像中的 librdkafka-dev,如下所示:>

I am trying to create a docker image with my go application. The application (which was developed on MacOS) depends on confluent-kafka-go which in turn depends on librdkafka-dev which I install in the Docker image like so:

FROM golang:1.1
RUN apt-get update
RUN apt-get -y install librdkafka-dev

VOLUME /workspace
WORKDIR /workspace/src/my/app/folder
ENTRYPOINT ["/bin/sh", "-c"]

我收到以下错误:

my/app/folder/vendor/github.com/confluentinc/confluent-kafka-go/kafka../folder/vendor/github.com/confluentinc/confluent-kafka-go/kafka/00version.go:44:2: error: #error "confluent-kafka-go 需要 librdkafka v0.11.5 或更高版本.安装最新的来自 Confluent 存储库的 librdkafka 版本,请参阅 http://docs.confluent.io/current/installation.html"

my/app/folder/vendor/github.com/confluentinc/confluent-kafka-go/kafka ../folder/vendor/github.com/confluentinc/confluent-kafka-go/kafka/00version.go:44:2: error: #error "confluent-kafka-go requires librdkafka v0.11.5 or later. Install the latest version of librdkafka from the Confluent repositories, see http://docs.confluent.io/current/installation.html"

据我所知,安装了最新版本.我该如何解决?

As far as I understand the latest version is installed. How can I fix it?

推荐答案

几周前我遇到了类似的问题.IIRC confluent-kafka-go 需要最新版本的 librdkafka-dev,它只是尚未发布到 alpine 或其他版本.我能够为 ubuntu 找到它,所以我的解决方案(比我希望的更复杂,但它有效)是从干净的 ubuntu 开始,安装 librdkafka-dev,安装 Go 版本我想要并在 docker 中编译.

I had a similar issue a few weeks ago. IIRC confluent-kafka-go requires a recent version of librdkafka-dev, which simply was not yet released to alpine or others. I was able to find it for ubuntu though, so my solution (which was more involved than I hoped for, but it worked), was to start from clean ubuntu, install librdkafka-dev, install Go version that I want and compile inside docker.

外观如下:

FROM ubuntu

# Install the C lib for kafka
RUN apt-get update
RUN apt-get install -y --no-install-recommends apt-utils wget gnupg software-properties-common
RUN apt-get install -y apt-transport-https ca-certificates
RUN wget -qO - https://packages.confluent.io/deb/5.1/archive.key | apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://packages.confluent.io/deb/5.1 stable main"
RUN apt-get update
RUN apt-get install -y librdkafka-dev

# Install Go
RUN add-apt-repository ppa:longsleep/golang-backports
RUN apt-get update
RUN apt-get install -y golang-1.11-go

# build the library
WORKDIR /go/src/gitlab.appsflyer.com/rantav/kafka-mirror-tester
COPY *.go ./
COPY // the rest of your go files. You may copy recursive if you want
COPY vendor vendor

RUN GOPATH=/go GOOS=linux /usr/lib/go-1.11/bin/go build -a -o main .

EXPOSE 8000

ENTRYPOINT ["./main"]

这篇关于在 Linux 上使用 confluent-kafka-go 构建 Go 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆