Simple and lightweight Linux C++11 encapsulation on librdkafka's C API.
- Use
std::unique_ptr<T>
to manage pointers likerd_kafka_t*
; - Use a simple config format. (I've tried TOML but found it unnecessary);
- Use variadic template to implement formatted error handle functions.
Why not use cppkafka
- Just for C++11 practice;
- Not require boost library.
I've only encapsulated some necessary functions to use, it's easy to extend these header files for your own use.
It's a header-only library and there's a sample Makefile, but ROOT_RDKAFKA
should be modified to librdkafka's root directory.
First open Makefile and modify ROOT_RDKAFKA
to your librdkafka install directory.
cd examples
make
Before run example programs, ensure that your path of librdkafka.so
has been added to LD_LIBRARY_PATH
.
$ ./producer
Usage: ./producer <topic-name> [config-path]
$ ./consumer
Usage: ./consumer <topic-name> [config-path]
Log is written to stderr, so you can redirect stderr to file (eg. 2>test.log
) to watch message in terminal and check for log later.
old version kafka must add these global configure(my kafka version is 0.9.0.1), see Broker version compatibility
api.version.request=false
broker.version.fallback=0.9.0.1
I've struggled with this problem for a while, it's really important to learn how Kafka works and read librdkafka WIKI first.
Old version SDK in rdkafka_*.hpp
is a mess, so I've started to write a new SDK in include/kafka_client
and write some tests in tests
.