GitHub - mfontanini/cppkafka: Modern C++ Apache Kafka client library (wrapper for librdkafka) (original) (raw)

cppkafka: high level C++ wrapper for rdkafka

Build status

cppkafka allows C++ applications to consume and produce messages using the Apache Kafka protocol. The library is built on top of librdkafka, and provides a high level API that uses modern C++ features to make it easier to write code while keeping the wrapper's performance overhead to a minimum.

Features

It's simple!

cppkafka's API is simple to use. For example, this code creates a producer that writes a message into some partition:

#include <cppkafka/cppkafka.h>

using namespace std; using namespace cppkafka;

int main() { // Create the config Configuration config = { { "metadata.broker.list", "127.0.0.1:9092" } };

// Create the producer
Producer producer(config);

// Produce a message!
string message = "hey there!";
producer.produce(MessageBuilder("my_topic").partition(0).payload(message));
producer.flush();

}

Compiling

In order to compile cppkafka you need:

Now, in order to build, just run:

mkdir build cd build cmake .. make make install

CMake options

The following cmake options can be specified:

Example:

cmake -DRDKAFKA_ROOT=/some/other/dir -DCPPKAFKA_BUILD_SHARED=OFF ...

Using

If you want to use cppkafka, you'll need to link your application with:

If using CMake, this is simplified by doing:

find_package(CppKafka REQUIRED)

target_link_libraries( CppKafka::cppkafka)

Documentation

You can generate the documentation by running make docs inside the build directory. This requires_Doxygen_ to be installed. The documentation will be written in html format at<build-dir>/docs/html/.

Make sure to check the wiki which includes some documentation about the project and some of its features.