confluentinc/librdkafka

GitHub: confluentinc/librdkafka

Apache Kafka 的高性能 C/C++ 客户端库,提供完整的消息生产、消费和集群管理功能。

Stars: 925 | Forks: 3242

# librdkafka - Apache Kafka® C/C++ 客户端库 版权所有 (c) 2012-2022,[Magnus Edenhill](http://www.edenhill.se/)。 2023 [Confluent Inc.](https://www.confluent.io/)。 [https://github.com/confluentinc/librdkafka](https://github.com/confluentinc/librdkafka) **librdkafka** 是 [Apache Kafka](https://kafka.apache.org/) 协议的 C 语言库实现,提供 Producer、Consumer 和 Admin 客户端。其设计初衷是追求消息传递的可靠性和高性能,目前的性能数据超过了 Producer 每秒 100 万条消息和 Consumer 每秒 300 万条消息。 **librdkafka** 采用 2-clause BSD 许可证授权。 KAFKA 是 The Apache Software Foundation 的注册商标,并已授权 librdkafka 使用。librdkafka 与 The Apache Software Foundation 无关联,也未得到其认可。 # 功能特性 * 完整的 Exactly-Once-Semantics (EOS) 支持 * 高级 Producer,包括 Idempotent 和 Transactional producers * 高级均衡 KafkaConsumer(要求 broker >= 0.9) * 简单(传统)consumer * Admin client * 压缩:snappy, gzip, lz4, zstd * [SSL](https://github.com/confluentinc/librdkafka/wiki/Using-SSL-with-librdkafka) 支持 * [SASL](https://github.com/confluentinc/librdkafka/wiki/Using-SASL-with-librdkafka) (GSSAPI/Kerberos/SSPI, PLAIN, SCRAM, OAUTHBEARER) 支持 * 完整的[支持的 KIP 列表](INTRODUCTION.md#supported-kips) * Broker 版本支持:>=0.8(参见 [Broker 版本兼容性](INTRODUCTION.md#broker-version-compatibility)) * 保证 C 和 C++ API 的稳定性(C 语言保证 ABI 安全) * [统计](STATISTICS.md)指标 * Debian 软件包:Debian 和 Ubuntu 中的 librdkafka1 和 librdkafka-dev * RPM 软件包:librdkafka 和 librdkafka-devel * Gentoo 软件包:dev-libs/librdkafka * 可移植:运行于 Linux, MacOS X, Windows, Solaris, FreeBSD, AIX, ... # 文档 * [C header](src/rdkafka.h) 和 [C++ header](src-cpp/rdkafkacpp.h) 中的 Public API。 * [INTRODUCTION.md](https://github.com/confluentinc/librdkafka/blob/master/INTRODUCTION.md) 中的介绍和手册。 * [CONFIGURATION.md](https://github.com/confluentinc/librdkafka/blob/master/CONFIGURATION.md) 中的配置属性。 * [STATISTICS.md](https://github.com/confluentinc/librdkafka/blob/master/STATISTICS.md) 中的统计指标。 * [常见问题](https://github.com/confluentinc/librdkafka/wiki)。 * 逐步教程 [Apache Kafka 和 C/C++ 入门](https://developer.confluent.io/get-started/c/)。 **注意**:`master` 分支处于活跃开发状态,生产环境请使用最新的 [release](https://github.com/confluentinc/librdkafka/releases)。 # 安装 ## 安装预编译包 在 Mac OSX 上,使用 homebrew 安装 librdkafka: ``` $ brew install librdkafka ``` 在 Debian 和 Ubuntu 上,从 Confluent APT 仓库安装 librdkafka, 请参阅[此处](https://docs.confluent.io/current/installation/installing_cp/deb-ubuntu.html#get-the-software)的说明,然后安装 librdkafka: ``` $ apt install librdkafka-dev ``` 在 RedHat, CentOS, Fedora 上,从 Confluent YUM 仓库安装 librdkafka, 说明在[这里](https://docs.confluent.io/current/installation/installing_cp/rhel-centos.html#get-the-software),然后安装 librdkafka: ``` $ yum install librdkafka-devel ``` 在 Windows 上,请在您的 Visual Studio 项目中引用 [librdkafka.redist](https://www.nuget.org/packages/librdkafka.redist/) NuGet 包。 对于其他平台,请遵循下面的源码构建说明。 ## 使用 vcpkg 安装 librdkafka 您可以使用 [vcpkg](https://github.com/Microsoft/vcpkg) 依赖管理器下载并安装 librdkafka: ``` # 安装 vcpkg(如果尚未安装) $ git clone https://github.com/Microsoft/vcpkg.git $ cd vcpkg $ ./bootstrap-vcpkg.sh $ ./vcpkg integrate install # 安装 librdkafka $ vcpkg install librdkafka ``` vcpkg 中的 librdkafka 包由 Microsoft 团队成员和社区贡献者保持最新。 如果版本过期,请在 vcpkg 仓库中 [创建 issue 或 pull request](https://github.com/Microsoft/vcpkg)。 ## 从源码构建 ### 环境要求 ``` 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) ``` **注意**:在 Producer 中静态链接 ZStd(要求 zstd >= 1.2.1) 可以在压缩帧头中编码原始大小, 这将加快 Consumer 的速度。 使用 `STATIC_LIB_libzstd=/path/to/libzstd.a ./configure --enable-static` 来启用静态 ZStd 链接。 MacOSX 示例: `STATIC_LIB_libzstd=$(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](README.win32)。 **注意**:有关实验性 CMake 构建(不支持),请参见 [CMake 说明](packaging/cmake/README.md)。 ## 代码用法 有关基础教程,请参阅 [Apache Kafka 和 C/C++ 入门](https://developer.confluent.io/get-started/c/)。 1. 请参阅 [examples 目录](examples/) 获取使用以下内容的代码: * Producers:基础 producers,idempotent producers,transactional producers。 * Consumers:基础 consumers,批量读取消息。 * 性能和延迟测试工具。 2. 请参阅 [examples GitHub 仓库](https://github.com/confluentinc/examples/tree/master/clients/cloud/c) 获取连接到基于 Apache Kafka 的云流数据服务的代码 3. 使用 `-lrdkafka` (C) 或 `-lrdkafka++` (C++) 链接您的程序。 ## 商业支持 商业支持由 [Confluent Inc](https://www.confluent.io/) 提供 ## 社区支持 **社区成员仅支持[最新的正式版本](https://github.com/confluentinc/librdkafka/releases)。** 使用 [GitHub Issues](https://github.com/confluentinc/librdkafka/issues) 提交错误报告和功能请求。 欢迎在 [Discussions](https://github.com/confluentinc/librdkafka/discussions) 论坛以及 [Confluent Community slack](https://launchpass.com/confluentcommunity) #clients 频道提问和讨论。 # 语言绑定 * C#/.NET: [confluent-kafka-dotnet](https://github.com/confluentinc/confluent-kafka-dotnet) (基于 [rdkafka-dotnet](https://github.com/ah-/rdkafka-dotnet)) * C++: [cppkafka](https://github.com/mfontanini/cppkafka) * C++: [modern-cpp-kafka](https://github.com/Morgan-Stanley/modern-cpp-kafka) * Common Lisp: [cl-rdkafka](https://github.com/SahilKang/cl-rdkafka) * D (C-like): [librdkafka](https://github.com/DlangApache/librdkafka/) * D (C++-like): [librdkafkad](https://github.com/tamediadigital/librdkafka-d) * Erlang: [erlkaf](https://github.com/silviucpp/erlkaf) * Go: [confluent-kafka-go](https://github.com/confluentinc/confluent-kafka-go) * Haskell (kafka, conduit, avro, schema registry): [hw-kafka](https://github.com/haskell-works/hw-kafka) * Kotlin Native: [Kafka-Kotlin-Native](https://github.com/icemachined/kafka-kotlin-native) * Lua: [luardkafka](https://github.com/mistsv/luardkafka) * Node.js: [node-rdkafka](https://github.com/Blizzard/node-rdkafka) * OCaml: [ocaml-kafka](https://github.com/didier-wenzek/ocaml-kafka) * Perl: [Net::Kafka](https://github.com/bookingcom/perl-Net-Kafka) * PHP: [php-rdkafka](https://github.com/arnaud-lb/php-rdkafka) * PHP: [php-simple-kafka-client](https://github.com/php-kafka/php-simple-kafka-client) * Python: [confluent-kafka-python](https://github.com/confluentinc/confluent-kafka-python) * Python: [PyKafka](https://github.com/Parsely/pykafka) * Ruby: [Hermann](https://github.com/reiseburo/hermann) * Ruby: [rdkafka-ruby](https://github.com/appsignal/rdkafka-ruby) * Rust: [rust-rdkafka](https://github.com/fede1024/rust-rdkafka) * Tcl: [KafkaTcl](https://github.com/flightaware/kafkatcl) * Shell: [kafkacat](https://github.com/edenhill/kafkacat) - Apache Kafka command line tool * Swift: [Perfect-Kafka](https://github.com/PerfectlySoft/Perfect-Kafka) 有关 librdkafka 用户的不完整列表,请参阅 [Powered by librdkafka](https://github.com/confluentinc/librdkafka/wiki/Powered-by-librdkafka)。
标签:Admin客户端, Apache Kafka, C/C++库, Confluent, Exactly-Once语义, IoT通信, IP 地址批量处理, librdkafka, SASL, SSL/TLS, 分布式系统, 响应大小分析, 大数据, 客户端加密, 客户端加密, 开发工具包, 开源库, 搜索引擎爬虫, 数据传输, 服务端开发, 流处理, 消息中间件, 消息可靠性, 消息队列, 消费者, 生产者, 目录扫描, 软件成分分析