librdkafka

Apache Kafka C/C++ 库。(The Apache Kafka C/C++ library)

Github stars Tracking Chart

librdkafka -- Apache Kafka C/C++ 客户端库

版权所有(c)2012-2019,Magnus Edenhill。

https://github.com/edenhill/librdkafka

librdkafka 是 Apache Kafka 协议的 C 库实现,提供生产者、消费者和管理客户端。它的设计考虑到了消息传递的可靠性和高性能,当前的数据对于生产者超过100 万 msgs/秒,对于消费者超过300万 msgs/秒。

librdkafka 根据 2-clause BSD 许可证获得许可。

特性

  • 高级生产者
  • 高级均衡 KafkaConsumer(要求 broker >= 0.9)
  • 简单(传统)消费者
  • 管理客户端
  • 压缩:snappy,gzip,lz4,zstd
  • SSL 支持
  • SASL(GSSAPI/Kerberos/SSPI,PLAIN,SCRAM,OAUTHBEARER)支持
  • Broker 版本支持:>= 0.8(参见 Broker 版本兼容性)
  • 稳定的 C&C++ API(C 保证 ABI 安全)
  • 统计指标
  • Debian 软件包:Debian 和 Ubuntu 中的 librdkafka1 和 librdkafka-dev
  • RPM 包:librdkafka 和 librdkafka-devel
  • Gentoo 包:dev-libs/librdkafka
  • Portable:运行在 Linux、OSX、Win32、Solaris、FreeBSD、AIX,...

文档

注:主分支正在积极开发中,生产使用请使用最新版本

安装

安装预构建的包

在 Mac OSX 上,使用 homebrew 安装 librdkafka:

$ brew install librdkafka

在 Debian 和 Ubuntu 上,从 Confluent APT 存储库安装 librdkafka,请参阅此处的说明,然后安装 librdkafka:

$ apt install librdkafka-dev

在 RedHat、CentOS、Fedora 上,从 Confluent YUM 存储库安装 librdkafka,这里有说明,然后安装 librdkafka:

$ yum install librdkafka-devel

在 Windows 上,在 Visual Studio 项目中引用 librdkafka.redist NuGet 包。

对于其他平台,请遵循以下源代码构建说明。

从源代码构建

要求

  • GNU toolchain
  • GNU make
  • pthreads
  • zlib-dev(可选,用于 gzip 压缩支持)
  • libssl-dev(可选,用于 SSL 和 SASL SCRAM 支持)
  • libsasl2-dev(可选,用于 SASL GSSAPI 支持)
  • libzstd-dev(可选,用于 ZStd 压缩支持)

注意:生成器中的 ZStd 静态链接(需要 zstd >=1.2.1)允许在压缩帧头中编码原始大小,这将加速消费者。使用 STATIC_LIB_zstd=/path/to/libzstd.a ./configure --enable-static 启用静态 ZStd 链接。 MacOSX 示例:STATIC_LIB_zstd=$(brew ls -v zstd | grep libzstd.a $) ./configure --enable-static

构建

./configure
  # Or, to automatically install dependencies using the system's package manager:
  # ./configure --install-deps
  # Or, build dependencies from source:
  # ./configure --install-deps --source-deps-only
  make
  sudo make install

:有关如何使用 Microsoft Visual Studio 在 Windows 上构建的说明,请参阅 README.win32

:请参阅 CMake 说明了解实验性 CMake 构建(不支持)。

在代码中使用

  1. 有关使用的代码,请参阅 Refer to the examples 目录
  • 生产者:基本生产者,幂等生产者
  • 消费者:基本消费者,阅读批量消息
  • 性能测试仪
  1. 有关连接到基于 Apache Kafka 的云流数据服务的代码,请参考 examples GitHub repo
  2. 用 -lrdkafka (C) 或 -lrdkafka++ (c++) 链接您的程序。

商业支持

Confluent Inc 提供商业支持。

社区支持

社区成员仅支持最后一个官方版本

使用 GitHub Issues 提交文件错误报告,功能请求和问题。

欢迎来自Confluent Community slack #clients 频道或 irc.freenode.org#apache-kafka 频道的问题和讨论。(First edition: vz revised at 2019.08.11)

语言绑定

librdkafka 用户

(First edition: vz revised at 2019.08.12)

Overview

Name With Ownerconfluentinc/librdkafka
Primary LanguageC
Program languageEmacs Lisp (Language Count: 12)
PlatformBSD, Linux, Mac, Solaris, Unix-like, Windows
License:Other
Release Count316
Last Release Namev2.4.0 (Posted on )
First Release Name0.7.0 (Posted on )
Created At2012-09-19 10:14:00
Pushed At2024-05-13 10:23:33
Last Commit At2024-05-08 15:41:26
Stargazers Count7.3k
Watchers Count411
Fork Count3.1k
Commits Count4.4k
Has Issues Enabled
Issues Count3000
Issue Open Count241
Pull Requests Count920
Pull Requests Open Count142
Pull Requests Close Count262
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

librdkafka - the Apache Kafka C/C++ client library

Copyright (c) 2012-2022, Magnus Edenhill.
2023 Confluent Inc..

https://github.com/confluentinc/librdkafka

librdkafka is a C library implementation of the
Apache Kafka protocol, providing Producer, Consumer
and Admin clients. It was designed with message delivery reliability
and high performance in mind, current figures exceed 1 million msgs/second for
the producer and 3 million msgs/second for the consumer.

librdkafka is licensed under the 2-clause BSD license.

KAFKA is a registered trademark of The Apache Software Foundation and
has been licensed for use by librdkafka. librdkafka has no
affiliation with and is not endorsed by The Apache Software Foundation.

Features

  • Full Exactly-Once-Semantics (EOS) support
  • High-level producer, including Idempotent and Transactional producers
  • High-level balanced KafkaConsumer (requires broker >= 0.9)
  • Simple (legacy) consumer
  • Admin client
  • Compression: snappy, gzip, lz4, zstd
  • SSL support
  • SASL (GSSAPI/Kerberos/SSPI, PLAIN, SCRAM, OAUTHBEARER) support
  • Full list of supported KIPs
  • Broker version support: >=0.8 (see Broker version compatibility)
  • Guaranteed API stability for C & C++ APIs (ABI safety guaranteed for C)
  • Statistics metrics
  • Debian package: librdkafka1 and librdkafka-dev in Debian and Ubuntu
  • RPM package: librdkafka and librdkafka-devel
  • Gentoo package: dev-libs/librdkafka
  • Portable: runs on Linux, MacOS X, Windows, Solaris, FreeBSD, AIX, ...

Documentation

NOTE: The master branch is actively developed, use latest release for production use.

Installation

Installing prebuilt packages

On Mac OSX, install librdkafka with homebrew:

$ brew install librdkafka

On Debian and Ubuntu, install librdkafka from the Confluent APT repositories,
see instructions here and then install librdkafka:

$ apt install librdkafka-dev

On RedHat, CentOS, Fedora, install librdkafka from the Confluent YUM repositories,
instructions here and then install librdkafka:

$ yum install librdkafka-devel

On Windows, reference librdkafka.redist NuGet package in your Visual Studio project.

For other platforms, follow the source building instructions below.

Installing librdkafka using vcpkg

You can download and install librdkafka using the vcpkg dependency manager:

# Install vcpkg if not already installed
$ git clone https://github.com/Microsoft/vcpkg.git
$ cd vcpkg
$ ./bootstrap-vcpkg.sh
$ ./vcpkg integrate install

# Install librdkafka
$ vcpkg install librdkafka

The librdkafka package in vcpkg is kept up to date by Microsoft team members and community contributors.
If the version is out of date, please create an issue or pull request on the vcpkg repository.

Build from source

Requirements

The GNU toolchain
GNU make
pthreads
zlib-dev (optional, for gzip compression support)
libssl-dev (optional, for SSL and SASL SCRAM support)
libsasl2-dev (optional, for SASL GSSAPI support)
libzstd-dev (optional, for ZStd compression support)
libcurl-dev (optional, for SASL OAUTHBEARER OIDC support)

NOTE: Static linking of ZStd (requires zstd >= 1.2.1) in the producer
enables encoding the original size in the compression frame header,
which will speed up the consumer.
Use STATIC_LIB_libzstd=/path/to/libzstd.a ./configure --enable-static
to enable static ZStd linking.
MacOSX example:
STATIC_LIB_libzstd=$(brew ls -v zstd | grep libzstd.a$) ./configure --enable-static

Building

  ./configure
  # Or, to automatically install dependencies using the system's package manager:
  # ./configure --install-deps
  # Or, build dependencies from source:
  # ./configure --install-deps --source-deps-only

  make
  sudo make install

NOTE: See README.win32 for instructions how to build
on Windows with Microsoft Visual Studio.

NOTE: See CMake instructions for experimental
CMake build (unsupported).

Usage in code

See getting Started with Apache Kafka and C/C++ for a basic tutorial.

  1. Refer to the examples directory for code using:

    • Producers: basic producers, idempotent producers, transactional producers.
    • Consumers: basic consumers, reading batches of messages.
    • Performance and latency testing tools.
  2. Refer to the examples GitHub repo for code connecting to a cloud streaming data service based on Apache Kafka

  3. Link your program with -lrdkafka (C) or -lrdkafka++ (C++).

Commercial support

Commercial support is available from Confluent Inc

Community support

Only the latest official release is supported for community members.

File bug reports and feature requests using GitHub Issues.

Questions and discussions are welcome on the Discussions forum, and on the Confluent Community slack #clients channel.

Language bindings

See Powered by librdkafka for an incomplete list of librdkafka users.

To the top