Skip to content

BewareMyPower/kafka-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rdkafka-client

Simple and lightweight Linux C++11 encapsulation on librdkafka's C API.

  1. Use std::unique_ptr<T> to manage pointers like rd_kafka_t*;
  2. Use a simple config format. (I've tried TOML but found it unnecessary);
  3. Use variadic template to implement formatted error handle functions.

Why not use cppkafka

  1. Just for C++11 practice;
  2. 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.

How to 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.

NOTE

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.

REFACTOR

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.

About

some encapsulation when use librdkafka

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published