https://github.com/maurodelazeri/kafkaz
High level C++ wrapper for librdkafka - https://github.com/edenhill/librdkafka
https://github.com/maurodelazeri/kafkaz
cpp kafka librdkafka
Last synced: 3 months ago
JSON representation
High level C++ wrapper for librdkafka - https://github.com/edenhill/librdkafka
- Host: GitHub
- URL: https://github.com/maurodelazeri/kafkaz
- Owner: maurodelazeri
- Created: 2020-02-19T23:47:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-02-20T13:43:47.000Z (over 5 years ago)
- Last Synced: 2025-01-05T09:19:47.547Z (5 months ago)
- Topics: cpp, kafka, librdkafka
- Language: C++
- Size: 23.4 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# KafkaZ
High level C++ wrapper for librdkafka - https://github.com/edenhill/librdkafka### Dependencies
* https://github.com/edenhill/librdkafka
* https://github.com/gabime/spdlog (this is not required, but im using for some logs)### Consumer example
```c++
#include
#include
#include "src/KafkaZ/ConsumerFactory.h"using namespace std;
int main(int argc, char **argv) {
std::string broker = "x.x.x.x:9092";
KafkaZ::BrokerSettings settings;
settings.Address = broker;
std::string topic = "test";std::unique_ptr consumer_ = KafkaZ::createConsumer(settings, broker);
consumer_->addTopic(topic);
//consumer_->addTopicAtTimestamp(topic,1582155192000ms); you can specify based on timestamp also
while (true) {
std::unique_ptr> KafkaMessage =
consumer_->poll();
if (KafkaMessage->first == KafkaZ::PollStatus::Message) {
cout << KafkaMessage->second.data() << endl;
}
}
return 0;
}
```### Producer example
```c++
#include
#include "src/KafkaZ/Producer.h"
#include "src/KafkaZ/ProducerTopic.h"using namespace std;
int main(int argc, char **argv) {
std::string broker = "x.x.x.x:9092";
KafkaZ::BrokerSettings settings;
settings.Address = broker;
std::string topic = "test";auto producer = std::make_shared(settings);
KafkaZ::ProducerTopic pt(producer, topic);
while (true) {
pt.produce("got it " + to_string(rand()));
sleep(1);
}
return 0;
}
```