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

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

问题描述

我正在尝试使用go应用程序创建一个docker映像。该应用程序(在MacOS上开发)取决于 confluent-kafka-go ,而后者又取决于 librdkafka-dev 我将其安装在Docker映像中是这样的:

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

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

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天全站免登陆