Add partitioner callback to topic configuration

This commit is contained in:
Matias Fontanini
2016-06-04 19:15:32 -07:00
parent 8e37440f58
commit 4fccf277e0
7 changed files with 102 additions and 9 deletions

View File

@@ -4,16 +4,18 @@
#include <string>
#include <memory>
#include <chrono>
#include <unordered_map>
#include <mutex>
#include <librdkafka/rdkafka.h>
#include "metadata.h"
#include "topic_partition.h"
#include "topic_partition_list.h"
#include "topic_configuration.h"
#include "configuration.h"
namespace cppkafka {
class Topic;
class TopicConfiguration;
class KafkaHandleBase {
public:
@@ -46,13 +48,17 @@ private:
static const std::chrono::milliseconds DEFAULT_TIMEOUT;
using HandlePtr = std::unique_ptr<rd_kafka_t, decltype(&rd_kafka_destroy)>;
using TopicConfigurationMap = std::unordered_map<std::string, TopicConfiguration>;
Topic get_topic(const std::string& name, rd_kafka_topic_conf_t* conf);
Metadata get_metadata(rd_kafka_topic_t* topic_ptr);
void save_topic_config(const std::string& topic_name, TopicConfiguration config);
HandlePtr handle_;
std::chrono::milliseconds timeout_ms_;
Configuration config_;
TopicConfigurationMap topic_configurations_;
std::mutex topic_configurations_mutex_;
};
} // cppkafka

View File

@@ -10,14 +10,19 @@ namespace cppkafka {
class Topic {
public:
static Topic make_non_owning(rd_kafka_topic_t* handle);
Topic(rd_kafka_topic_t* handle);
std::string get_name() const;
rd_kafka_topic_t* get_handle() const;
private:
using HandlePtr = std::unique_ptr<rd_kafka_topic_t, decltype(&rd_kafka_topic_destroy)>;
struct NonOwningTag { };
Topic(rd_kafka_topic_t* handle, NonOwningTag);
HandlePtr handle_;
};

View File

@@ -2,26 +2,40 @@
#define CPPKAFKA_TOPIC_CONFIGURATION_H
#include <string>
#include <functional>
#include <librdkafka/rdkafka.h>
#include "clonable_ptr.h"
namespace cppkafka {
class Topic;
class Buffer;
class TopicConfiguration {
public:
using PartitionerCallback = std::function<int32_t(const Topic&, const Buffer& key,
int32_t partition_count)>;
TopicConfiguration();
void set(const std::string& name, const std::string& value);
void set_partitioner_callback(PartitionerCallback callback);
void set_as_opaque();
const PartitionerCallback& get_partitioner_callback() const;
rd_kafka_topic_conf_t* get_handle() const;
private:
using HandlePtr = ClonablePtr<rd_kafka_topic_conf_t, decltype(&rd_kafka_topic_conf_destroy),
using HandlePtr = ClonablePtr<rd_kafka_topic_conf_t,
decltype(&rd_kafka_topic_conf_destroy),
decltype(&rd_kafka_topic_conf_dup)>;
TopicConfiguration(rd_kafka_topic_conf_t* ptr);
static HandlePtr make_handle(rd_kafka_topic_conf_t* ptr);
HandlePtr handle_;
PartitionerCallback partitioner_callback_;
};
} // cppkafka