mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka.git
synced 2025-11-22 12:44:50 +00:00
Add initial producer code
This commit is contained in:
45
src/kafka_handle_base.cpp
Normal file
45
src/kafka_handle_base.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "kafka_handle_base.h"
|
||||
#include "exceptions.h"
|
||||
#include "topic_configuration.h"
|
||||
#include "topic.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace cppkafka {
|
||||
|
||||
KafkaHandleBase::KafkaHandleBase()
|
||||
: handle_(nullptr, nullptr) {
|
||||
|
||||
}
|
||||
|
||||
KafkaHandleBase::KafkaHandleBase(rd_kafka_t* handle)
|
||||
: handle_(handle, &rd_kafka_destroy) {
|
||||
|
||||
}
|
||||
|
||||
void KafkaHandleBase::set_handle(rd_kafka_t* handle) {
|
||||
handle_ = HandlePtr(handle, &rd_kafka_destroy);
|
||||
}
|
||||
|
||||
rd_kafka_t* KafkaHandleBase::get_handle() {
|
||||
return handle_.get();
|
||||
}
|
||||
|
||||
Topic KafkaHandleBase::get_topic(const string& name) {
|
||||
rd_kafka_topic_t* topic = rd_kafka_topic_new(handle_.get(), name.data(), nullptr);
|
||||
if (!topic) {
|
||||
throw Exception("Failed to create topic handle");
|
||||
}
|
||||
return Topic(topic);
|
||||
}
|
||||
|
||||
Topic KafkaHandleBase::get_topic(const string& name, const TopicConfiguration& config) {
|
||||
rd_kafka_topic_t* topic = rd_kafka_topic_new(handle_.get(), name.data(),
|
||||
config.get_handle());
|
||||
if (!topic) {
|
||||
throw Exception("Failed to create topic handle");
|
||||
}
|
||||
return Topic(topic);
|
||||
}
|
||||
|
||||
} // cppkafka
|
||||
Reference in New Issue
Block a user