mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka.git
synced 2025-11-26 22:54:49 +00:00
Allow getting config options and add multiple overloads for set
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "configuration.h"
|
||||
#include <vector>
|
||||
#include <librdkafka/rdkafka.h>
|
||||
#include "exceptions.h"
|
||||
#include "message.h"
|
||||
@@ -7,6 +8,7 @@
|
||||
|
||||
using std::string;
|
||||
using std::move;
|
||||
using std::vector;
|
||||
|
||||
using boost::optional;
|
||||
|
||||
@@ -146,6 +148,17 @@ rd_kafka_conf_t* Configuration::get_handle() const {
|
||||
return handle_.get();
|
||||
}
|
||||
|
||||
string Configuration::get(const string& name) const {
|
||||
size_t size = 0;
|
||||
auto result = rd_kafka_conf_get(handle_.get(), name.data(), nullptr, &size);
|
||||
if (result != RD_KAFKA_CONF_OK) {
|
||||
throw ConfigOptionNotFound(name);
|
||||
}
|
||||
vector<char> buffer(size);
|
||||
rd_kafka_conf_get(handle_.get(), name.data(), buffer.data(), &size);
|
||||
return string(buffer.data());
|
||||
}
|
||||
|
||||
const Configuration::DeliveryReportCallback& Configuration::get_delivery_report_callback() const {
|
||||
return delivery_report_callback_;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,13 @@ ConfigException::ConfigException(const string& config_name, const string& error)
|
||||
|
||||
}
|
||||
|
||||
// ConfigOptionNotFound
|
||||
|
||||
ConfigOptionNotFound::ConfigOptionNotFound(const string& config_name)
|
||||
: Exception(config_name + " not found") {
|
||||
|
||||
}
|
||||
|
||||
// HandleException
|
||||
|
||||
HandleException::HandleException(rd_kafka_resp_err_t error_code)
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#include "topic_configuration.h"
|
||||
#include <vector>
|
||||
#include <librdkafka/rdkafka.h>
|
||||
#include "exceptions.h"
|
||||
#include "topic.h"
|
||||
#include "buffer.h"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace cppkafka {
|
||||
|
||||
@@ -63,6 +65,17 @@ rd_kafka_topic_conf_t* TopicConfiguration::get_handle() const {
|
||||
return handle_.get();
|
||||
}
|
||||
|
||||
string TopicConfiguration::get(const string& name) const {
|
||||
size_t size = 0;
|
||||
auto result = rd_kafka_topic_conf_get(handle_.get(), name.data(), nullptr, &size);
|
||||
if (result != RD_KAFKA_CONF_OK) {
|
||||
throw ConfigOptionNotFound(name);
|
||||
}
|
||||
vector<char> buffer(size);
|
||||
rd_kafka_topic_conf_get(handle_.get(), name.data(), buffer.data(), &size);
|
||||
return string(buffer.data());
|
||||
}
|
||||
|
||||
TopicConfiguration::HandlePtr TopicConfiguration::make_handle(rd_kafka_topic_conf_t* ptr) {
|
||||
return HandlePtr(ptr, &rd_kafka_topic_conf_destroy, &rd_kafka_topic_conf_dup);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user