【问题标题】:Building Go Application using confluent-kafka-go on Linux在 Linux 上使用 confluent-kafka-go 构建 Go 应用程序
【发布时间】:2019-06-09 16:08:30
【问题描述】:

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

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"

据我了解,最新版本已安装。 我该如何解决?

【问题讨论】:

    标签: docker go apache-kafka


    【解决方案1】:

    几周前我遇到了类似的问题。 IIRC confluent-kafka-go 需要最新版本的 librdkafka-dev,它还没有发布给 alpine 或其他人。 虽然我能够为 ubuntu 找到它,所以我的解决方案(这比我希望的更多,但它有效)是从干净的 ubuntu 开始,安装librdkafka-dev,安装我想要的 Go 版本并在 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"]
    

    【讨论】:

      【解决方案2】:

      您可以在 apt-get 命令中指定要安装的软件包版本。 例如

      apt-get install librdkafka-dev=0.11.6~1confluent5.0.1-1
      

      如果这不起作用,那么我认为 apt 源没有 librdkafka 的 0.11.5 版本。 您可以在/etc/apt/sources.list 中添加具有正确版本的 librdkafka 的存储库,如下所述: https://docs.confluent.io/current/installation/installing_cp/deb-ubuntu.html#systemd-ubuntu-debian-install

      【讨论】:

      • 谢谢 - 我会试一试
      猜你喜欢
      • 1970-01-01
      • 2016-12-24
      • 1970-01-01
      • 1970-01-01
      • 2020-11-07
      • 2017-04-20
      • 1970-01-01
      • 2021-04-25
      • 2012-03-23
      相关资源
      最近更新 更多