mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka.git
synced 2026-01-08 13:01:30 +00:00
Add some documentation
This commit is contained in:
@@ -20,7 +20,7 @@ if (ENABLE_ZOOKEEPER)
|
||||
set(ZOOKEEPER_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/zookeeper/zookeeper_watcher.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/zookeeper/zookeeper_pool.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/zookeeper/zookeeper_subscriber.cpp)
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/zookeeper/zookeeper_subscription.cpp)
|
||||
# Add json library as include dir (header only)
|
||||
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/json)
|
||||
set(SOURCES ${SOURCES} ${ZOOKEEPER_SOURCES})
|
||||
|
||||
@@ -126,9 +126,11 @@ void Consumer::async_commit(const TopicPartitionList& topic_partitions) {
|
||||
commit(topic_partitions, true);
|
||||
}
|
||||
|
||||
KafkaHandleBase::OffsetTuple Consumer::get_offsets(const string& topic, int partition) const {
|
||||
KafkaHandleBase::OffsetTuple Consumer::get_offsets(const TopicPartition& topic_partition) const {
|
||||
int64_t low;
|
||||
int64_t high;
|
||||
const string& topic = topic_partition.get_topic();
|
||||
const int partition = topic_partition.get_partition();
|
||||
rd_kafka_resp_err_t result = rd_kafka_get_watermark_offsets(get_handle(), topic.data(),
|
||||
partition, &low, &high);
|
||||
check_error(result);
|
||||
@@ -152,12 +154,18 @@ Consumer::get_offsets_position(const TopicPartitionList& topic_partitions) const
|
||||
return convert(topic_list_handle);
|
||||
}
|
||||
|
||||
TopicPartitionList Consumer::get_subscription() const {
|
||||
vector<string> Consumer::get_subscription() const {
|
||||
rd_kafka_resp_err_t error;
|
||||
rd_kafka_topic_partition_list_t* list = nullptr;
|
||||
error = rd_kafka_subscription(get_handle(), &list);
|
||||
check_error(error);
|
||||
return convert(make_handle(list));
|
||||
|
||||
auto handle = make_handle(list);
|
||||
vector<string> output;
|
||||
for (const auto& topic_partition : convert(handle)) {
|
||||
output.push_back(topic_partition.get_topic());
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
TopicPartitionList Consumer::get_assignment() const {
|
||||
|
||||
@@ -91,10 +91,12 @@ Topic KafkaHandleBase::get_topic(const string& name, TopicConfiguration config)
|
||||
return get_topic(name, rd_kafka_topic_conf_dup(handle));
|
||||
}
|
||||
|
||||
KafkaHandleBase::OffsetTuple KafkaHandleBase::query_offsets(const string& topic,
|
||||
int partition) const {
|
||||
KafkaHandleBase::OffsetTuple
|
||||
KafkaHandleBase::query_offsets(const TopicPartition& topic_partition) const {
|
||||
int64_t low;
|
||||
int64_t high;
|
||||
const string& topic = topic_partition.get_topic();
|
||||
const int partition = topic_partition.get_partition();
|
||||
rd_kafka_resp_err_t result = rd_kafka_query_watermark_offsets(handle_.get(), topic.data(),
|
||||
partition, &low, &high,
|
||||
timeout_ms_.count());
|
||||
@@ -144,8 +146,8 @@ void KafkaHandleBase::set_handle(rd_kafka_t* handle) {
|
||||
rd_kafka_brokers_add(handle_.get(), brokers.data());
|
||||
rd_kafka_poll(handle_.get(), 10);
|
||||
};
|
||||
ZookeeperSubscriber subscriber = pool.subscribe(endpoint, timeout, callback);
|
||||
zookeeper_subscriber_.reset(new ZookeeperSubscriber(move(subscriber)));
|
||||
ZookeeperSubscription subscriber = pool.subscribe(endpoint, timeout, callback);
|
||||
zookeeper_subscription_.reset(new ZookeeperSubscription(move(subscriber)));
|
||||
callback(pool.get_brokers(endpoint));
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
*/
|
||||
|
||||
#include "zookeeper/zookeeper_pool.h"
|
||||
#include "zookeeper/zookeeper_subscriber.h"
|
||||
#include "zookeeper/zookeeper_subscription.h"
|
||||
#include "exceptions.h"
|
||||
|
||||
using std::string;
|
||||
@@ -45,7 +45,7 @@ ZookeeperPool& ZookeeperPool::instance() {
|
||||
return the_instance;
|
||||
}
|
||||
|
||||
ZookeeperSubscriber ZookeeperPool::subscribe(const string& endpoint,
|
||||
ZookeeperSubscription ZookeeperPool::subscribe(const string& endpoint,
|
||||
milliseconds receive_timeout,
|
||||
ZookeeperWatcher::WatcherCallback callback) {
|
||||
lock_guard<mutex> _(watchers_mutex_);
|
||||
@@ -55,10 +55,10 @@ ZookeeperSubscriber ZookeeperPool::subscribe(const string& endpoint,
|
||||
forward_as_tuple(endpoint, receive_timeout)).first;
|
||||
}
|
||||
string id = iter->second.subscribe(move(callback));
|
||||
return ZookeeperSubscriber(endpoint, id);
|
||||
return ZookeeperSubscription(endpoint, id);
|
||||
}
|
||||
|
||||
void ZookeeperPool::unsubscribe(const ZookeeperSubscriber& subscriber) {
|
||||
void ZookeeperPool::unsubscribe(const ZookeeperSubscription& subscriber) {
|
||||
lock_guard<mutex> _(watchers_mutex_);
|
||||
auto iter = watchers_.find(subscriber.get_endpoint());
|
||||
if (iter != watchers_.end()) {
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
#include "zookeeper/zookeeper_subscriber.h"
|
||||
#include "zookeeper/zookeeper_pool.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace cppkafka {
|
||||
|
||||
ZookeeperSubscriber::ZookeeperSubscriber(string endpoint, string subscription_id)
|
||||
: endpoint_(move(endpoint)), subscription_id_(move(subscription_id)) {
|
||||
|
||||
}
|
||||
|
||||
ZookeeperSubscriber::~ZookeeperSubscriber() {
|
||||
ZookeeperPool::instance().unsubscribe(*this);
|
||||
}
|
||||
|
||||
const string& ZookeeperSubscriber::get_endpoint() const {
|
||||
return endpoint_;
|
||||
}
|
||||
|
||||
const string& ZookeeperSubscriber::get_subscription_id() const {
|
||||
return subscription_id_;
|
||||
}
|
||||
|
||||
} // cppkafka
|
||||
25
src/zookeeper/zookeeper_subscription.cpp
Normal file
25
src/zookeeper/zookeeper_subscription.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "zookeeper/zookeeper_subscription.h"
|
||||
#include "zookeeper/zookeeper_pool.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace cppkafka {
|
||||
|
||||
ZookeeperSubscription::ZookeeperSubscription(string endpoint, string subscription_id)
|
||||
: endpoint_(move(endpoint)), subscription_id_(move(subscription_id)) {
|
||||
|
||||
}
|
||||
|
||||
ZookeeperSubscription::~ZookeeperSubscription() {
|
||||
ZookeeperPool::instance().unsubscribe(*this);
|
||||
}
|
||||
|
||||
const string& ZookeeperSubscription::get_endpoint() const {
|
||||
return endpoint_;
|
||||
}
|
||||
|
||||
const string& ZookeeperSubscription::get_subscription_id() const {
|
||||
return subscription_id_;
|
||||
}
|
||||
|
||||
} // cppkafka
|
||||
Reference in New Issue
Block a user