簡體   English   中英

在Linux上使用confluent-kafka-go構建Go應用程序

[英]Building Go Application using confluent-kafka-go on Linux

我正在嘗試使用go應用程序創建一個docker鏡像。 應用程序(在MacOS上開發)依賴於confluent-kafka-go ,而后者依賴於我在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“confluent-kafka-go需要librdkafka v0.11.5或更高版本。從Confluent存儲庫安裝最新版本的librdkafka,請參閱http://docs.confluent.io/current/installation.html

據我了解的最新版本安裝 我該如何解決?

幾個星期前,我有類似的問題。 IIRC confluent-kafka-go需要最新版本的librdkafka-dev ,它尚未發布給alpine或其他人。 我能夠為ubuntu找到它,所以我的解決方案(比我希望的更多,但它有效),是從干凈的ubuntu開始,安裝librdkafka-dev ,安裝我想要的Go版本並在librdkafka-dev編譯。

以下是它的外觀:

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"]

您可以在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的安裝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM