mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka.git
synced 2025-11-02 11:37:50 +00:00
Add metadata objects and tests for them
This commit is contained in:
@@ -15,7 +15,6 @@ public:
|
||||
Buffer(const T* data, size_t size)
|
||||
: data_(reinterpret_cast<const DataType*>(data)), size_(size) {
|
||||
static_assert(sizeof(T) == 1, "Buffer must point to elements of 1 byte");
|
||||
|
||||
}
|
||||
|
||||
Buffer(const Buffer&) = delete;
|
||||
|
@@ -26,7 +26,6 @@ public:
|
||||
Consumer& operator=(Consumer&&) = delete;
|
||||
~Consumer();
|
||||
|
||||
void set_timeout(const std::chrono::milliseconds timeout);
|
||||
void set_assignment_callback(AssignmentCallback callback);
|
||||
void set_revocation_callback(RevocationCallback callback);
|
||||
void set_rebalance_error_callback(RebalanceErrorCallback callback);
|
||||
@@ -50,8 +49,6 @@ public:
|
||||
|
||||
Message poll();
|
||||
private:
|
||||
static const std::chrono::milliseconds DEFAULT_TIMEOUT;
|
||||
|
||||
static void rebalance_proxy(rd_kafka_t *handle, rd_kafka_resp_err_t error,
|
||||
rd_kafka_topic_partition_list_t *partitions, void *opaque);
|
||||
|
||||
@@ -59,7 +56,6 @@ private:
|
||||
void commit(const TopicPartitionList& topic_partitions, bool async);
|
||||
void handle_rebalance(rd_kafka_resp_err_t err, const TopicPartitionList& topic_partitions);
|
||||
|
||||
std::chrono::milliseconds timeout_ms_;
|
||||
AssignmentCallback assignment_callback_;
|
||||
RevocationCallback revocation_callback_;
|
||||
RebalanceErrorCallback rebalance_error_callback_;
|
||||
|
@@ -3,8 +3,10 @@
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
#include <librdkafka/rdkafka.h>
|
||||
#include "topic_partition_list.h"
|
||||
#include "metadata.h"
|
||||
|
||||
namespace cppkafka {
|
||||
|
||||
@@ -22,9 +24,14 @@ public:
|
||||
void pause_partitions(const TopicPartitionList& topic_partitions);
|
||||
void resume_partitions(const TopicPartitionList& topic_partitions);
|
||||
|
||||
void set_timeout(const std::chrono::milliseconds& timeout);
|
||||
|
||||
rd_kafka_t* get_handle();
|
||||
Topic get_topic(const std::string& name);
|
||||
Topic get_topic(const std::string& name, TopicConfiguration config);
|
||||
Metadata get_metadata();
|
||||
Metadata get_metadata(const Topic& topic);
|
||||
std::chrono::milliseconds get_timeout() const;
|
||||
protected:
|
||||
KafkaHandleBase();
|
||||
KafkaHandleBase(rd_kafka_t* handle);
|
||||
@@ -32,11 +39,15 @@ protected:
|
||||
void set_handle(rd_kafka_t* handle);
|
||||
void check_error(rd_kafka_resp_err_t error);
|
||||
private:
|
||||
static const std::chrono::milliseconds DEFAULT_TIMEOUT;
|
||||
|
||||
using HandlePtr = std::unique_ptr<rd_kafka_t, decltype(&rd_kafka_destroy)>;
|
||||
|
||||
Topic get_topic(const std::string& name, rd_kafka_topic_conf_t* conf);
|
||||
Metadata get_metadata(rd_kafka_topic_t* topic_ptr);
|
||||
|
||||
HandlePtr handle_;
|
||||
std::chrono::milliseconds timeout_ms_;
|
||||
};
|
||||
|
||||
} // cppkafka
|
||||
|
72
include/cppkafka/metadata.h
Normal file
72
include/cppkafka/metadata.h
Normal file
@@ -0,0 +1,72 @@
|
||||
#ifndef CPPKAFKA_METADATA_H
|
||||
#define CPPKAFKA_METADATA_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <unordered_set>
|
||||
#include <librdkafka/rdkafka.h>
|
||||
|
||||
namespace cppkafka {
|
||||
|
||||
class PartitionMetadata {
|
||||
public:
|
||||
PartitionMetadata(const rd_kafka_metadata_partition& partition);
|
||||
|
||||
uint32_t get_id() const;
|
||||
rd_kafka_resp_err_t get_error() const;
|
||||
int32_t get_leader() const;
|
||||
const std::vector<int32_t>& get_replicas() const;
|
||||
const std::vector<int32_t>& get_in_sync_replica_brokers() const;
|
||||
private:
|
||||
int32_t id_;
|
||||
rd_kafka_resp_err_t error_;
|
||||
int32_t leader_;
|
||||
std::vector<int32_t> replicas_;
|
||||
std::vector<int32_t> isrs_;
|
||||
};
|
||||
|
||||
class TopicMetadata {
|
||||
public:
|
||||
TopicMetadata(const rd_kafka_metadata_topic& topic);
|
||||
|
||||
const std::string& get_topic() const;
|
||||
rd_kafka_resp_err_t get_error() const;
|
||||
const std::vector<PartitionMetadata>& get_partitions() const;
|
||||
private:
|
||||
std::string topic_;
|
||||
rd_kafka_resp_err_t error_;
|
||||
std::vector<PartitionMetadata> partitions_;
|
||||
};
|
||||
|
||||
class BrokerMetadata {
|
||||
public:
|
||||
BrokerMetadata(const rd_kafka_metadata_broker_t& broker);
|
||||
|
||||
const std::string& get_host() const;
|
||||
int32_t get_id() const;
|
||||
uint16_t get_port() const;
|
||||
private:
|
||||
const std::string host_;
|
||||
int32_t id_;
|
||||
uint16_t port_;
|
||||
};
|
||||
|
||||
class Metadata {
|
||||
public:
|
||||
Metadata(const rd_kafka_metadata_t* ptr);
|
||||
|
||||
std::vector<BrokerMetadata> get_brokers() const;
|
||||
std::vector<TopicMetadata> get_topics() const;
|
||||
std::vector<TopicMetadata> get_topics(const std::unordered_set<std::string>& topics) const;
|
||||
std::vector<TopicMetadata> get_topics(const std::string& prefix) const;
|
||||
private:
|
||||
using HandlePtr = std::unique_ptr<const rd_kafka_metadata_t, decltype(&rd_kafka_metadata_destroy)>;
|
||||
|
||||
HandlePtr handle_;
|
||||
};
|
||||
|
||||
} // cppkafka
|
||||
|
||||
#endif // CPPKAFKA_METADATA_H
|
Reference in New Issue
Block a user