mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka.git
synced 2025-11-06 05:27:53 +00:00
Add zookeeper support
This commit is contained in:
@@ -33,6 +33,9 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <zookeeper/zookeeper.h>
|
||||
|
||||
namespace cppkafka {
|
||||
@@ -41,21 +44,33 @@ class ZookeeperWatcher {
|
||||
public:
|
||||
static const std::chrono::milliseconds DEFAULT_RECEIVE_TIMEOUT;
|
||||
|
||||
using WatcherCallback = std::function<void(const std::string& brokers)>;
|
||||
|
||||
ZookeeperWatcher(const std::string& endpoint);
|
||||
ZookeeperWatcher(const std::string& endpoint, std::chrono::milliseconds receive_timeout);
|
||||
|
||||
void setup_watcher();
|
||||
|
||||
std::string subscribe(WatcherCallback callback);
|
||||
void unsubscribe(const std::string& id);
|
||||
|
||||
std::string get_brokers();
|
||||
size_t get_subscriber_count() const;
|
||||
private:
|
||||
using HandlePtr = std::unique_ptr<zhandle_t, decltype(&zookeeper_close)>;
|
||||
|
||||
static const std::string BROKERS_PATH;
|
||||
|
||||
using HandlePtr = std::unique_ptr<zhandle_t, decltype(&zookeeper_close)>;
|
||||
using CallbackMap = std::map<std::string, WatcherCallback>;
|
||||
|
||||
static void handle_event_proxy(zhandle_t* zh, int type, int state, const char* path,
|
||||
void* ctx);
|
||||
void handle_event(int type, int state, const char* path);
|
||||
std::string generate_id();
|
||||
|
||||
HandlePtr handle_;
|
||||
CallbackMap callbacks_;
|
||||
mutable std::mutex callbacks_mutex_;
|
||||
size_t id_counter_{0};
|
||||
};
|
||||
|
||||
} // cppkafka
|
||||
|
||||
Reference in New Issue
Block a user