mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka.git
synced 2025-11-01 19:18:04 +00:00
Allow getting config options and add multiple overloads for set
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "topic_partition_list.h"
|
||||
#include "topic_configuration.h"
|
||||
#include "clonable_ptr.h"
|
||||
#include "configuration_base.h"
|
||||
|
||||
namespace cppkafka {
|
||||
|
||||
@@ -18,7 +19,7 @@ class Producer;
|
||||
class Consumer;
|
||||
class KafkaHandleBase;
|
||||
|
||||
class Configuration {
|
||||
class Configuration : public ConfigurationBase<Configuration> {
|
||||
public:
|
||||
using DeliveryReportCallback = std::function<void(Producer& producer, const Message&)>;
|
||||
using OffsetCommitCallback = std::function<void(Consumer& consumer, rd_kafka_resp_err_t,
|
||||
@@ -35,6 +36,8 @@ public:
|
||||
using StatsCallback = std::function<void(KafkaHandleBase& handle, const std::string& json)>;
|
||||
using SocketCallback = std::function<int(int domain, int type, int protoco)>;
|
||||
|
||||
using ConfigurationBase<Configuration>::set;
|
||||
|
||||
Configuration();
|
||||
|
||||
void set(const std::string& name, const std::string& value);
|
||||
@@ -48,6 +51,7 @@ public:
|
||||
void set_default_topic_configuration(boost::optional<TopicConfiguration> config);
|
||||
|
||||
rd_kafka_conf_t* get_handle() const;
|
||||
std::string get(const std::string& name) const;
|
||||
const DeliveryReportCallback& get_delivery_report_callback() const;
|
||||
const OffsetCommitCallback& get_offset_commit_callback() const;
|
||||
const ErrorCallback& get_error_callback() const;
|
||||
|
||||
33
include/cppkafka/configuration_base.h
Normal file
33
include/cppkafka/configuration_base.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef CPPKAFKA_CONFIGURATION_BASE_H
|
||||
#define CPPKAFKA_CONFIGURATION_BASE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace cppkafka {
|
||||
|
||||
template <typename Concrete>
|
||||
class ConfigurationBase {
|
||||
public:
|
||||
void set(const std::string& name, bool value) {
|
||||
proxy_set(name, value ? "true" : "false");
|
||||
}
|
||||
|
||||
// Overload for any integral value
|
||||
template <typename T,
|
||||
typename = typename std::enable_if<std::is_integral<T>::value>::type>
|
||||
void set(const std::string& name, T value) {
|
||||
proxy_set(name, std::to_string(value));
|
||||
}
|
||||
|
||||
void set(const std::string& name, const char* value) {
|
||||
proxy_set(name, value);
|
||||
}
|
||||
private:
|
||||
void proxy_set(const std::string& name, const std::string& value) {
|
||||
static_cast<Concrete&>(*this).set(name, value);
|
||||
}
|
||||
};
|
||||
|
||||
} // cppkafka
|
||||
|
||||
#endif // CPPKAFKA_CONFIGURATION_BASE_H
|
||||
@@ -21,6 +21,11 @@ public:
|
||||
ConfigException(const std::string& config_name, const std::string& error);
|
||||
};
|
||||
|
||||
class ConfigOptionNotFound : public Exception {
|
||||
public:
|
||||
ConfigOptionNotFound(const std::string& config_name);
|
||||
};
|
||||
|
||||
class HandleException : public Exception {
|
||||
public:
|
||||
HandleException(rd_kafka_resp_err_t error_code);
|
||||
|
||||
@@ -5,17 +5,20 @@
|
||||
#include <functional>
|
||||
#include <librdkafka/rdkafka.h>
|
||||
#include "clonable_ptr.h"
|
||||
#include "configuration_base.h"
|
||||
|
||||
namespace cppkafka {
|
||||
|
||||
class Topic;
|
||||
class Buffer;
|
||||
|
||||
class TopicConfiguration {
|
||||
class TopicConfiguration : public ConfigurationBase<TopicConfiguration> {
|
||||
public:
|
||||
using PartitionerCallback = std::function<int32_t(const Topic&, const Buffer& key,
|
||||
int32_t partition_count)>;
|
||||
|
||||
using ConfigurationBase<TopicConfiguration>::set;
|
||||
|
||||
TopicConfiguration();
|
||||
|
||||
void set(const std::string& name, const std::string& value);
|
||||
@@ -26,6 +29,7 @@ public:
|
||||
|
||||
const PartitionerCallback& get_partitioner_callback() const;
|
||||
rd_kafka_topic_conf_t* get_handle() const;
|
||||
std::string get(const std::string& name) const;
|
||||
private:
|
||||
using HandlePtr = ClonablePtr<rd_kafka_topic_conf_t,
|
||||
decltype(&rd_kafka_topic_conf_destroy),
|
||||
|
||||
Reference in New Issue
Block a user