Remove zookeeper support

This commit is contained in:
Matias Fontanini
2016-06-16 20:22:36 -07:00
parent e1c2ee34fe
commit 0fb0afc4f4
27 changed files with 42 additions and 800 deletions

View File

@@ -4,4 +4,3 @@ install(
DESTINATION include/cppkafka
COMPONENT Headers
)
add_subdirectory(zookeeper)

View File

@@ -1,7 +0,0 @@
#ifndef CPPKAFKA_CONFIG_H
#define CPPKAFKA_CONFIG_H
/* Define if the zookeeper extensions are enabled */
#cmakedefine CPPKAFKA_HAVE_ZOOKEEPER
#endif // CPPKAFKA_CONFIG_H

View File

@@ -87,16 +87,6 @@ public:
*
* This will call rd_kafka_conf_set under the hood.
*
* If the zookeeper extension is enabled (cppkafka is build with -DENABLE_ZOOKEEPER=1), then
* this accepts 2 extra attribute names:
*
* - "zookeeper" which indicates the zookeeper endpoint to connect to
* - "zookeeper.receive.timeout.ms" which indicates the zookeeper receive timeout
*
* When the "zookeeper" attribute is used, a Consumer or Producer constructed using this
* configuration will use zookeeper under the hood to get the broker list and watch for
* broker updates.
*
* \param name The name of the attribute
* \param value The value of the attribute
*/
@@ -204,10 +194,8 @@ public:
*/
boost::optional<TopicConfiguration>& get_default_topic_configuration();
private:
static const std::unordered_set<std::string> VALID_EXTENSIONS;
using HandlePtr = ClonablePtr<rd_kafka_conf_t, decltype(&rd_kafka_conf_destroy),
decltype(&rd_kafka_conf_dup)>;
using PropertiesMap = std::unordered_map<std::string, std::string>;
Configuration(rd_kafka_conf_t* ptr);
static HandlePtr make_handle(rd_kafka_conf_t* ptr);
@@ -221,7 +209,6 @@ private:
LogCallback log_callback_;
StatsCallback stats_callback_;
SocketCallback socket_callback_;
PropertiesMap extension_properties_;
};
} // cppkafka

View File

@@ -52,10 +52,9 @@ class TopicConfiguration;
* Semi-simple code showing how to use this class
*
* \code
* // Create a configuration and set the group.id and zookeeper fields
* // Create a configuration and set the group.id and broker list fields
* Configuration config;
* // This is only valid when using the zookeeper extension
* config.set("zookeeper", "127.0.0.1:2181");
* config.set("metadata.broker.list", "127.0.0.1:9092");
* config.set("group.id", "foo");
*
* // Create a consumer

View File

@@ -76,14 +76,6 @@ private:
rd_kafka_resp_err_t error_code_;
};
/**
* An exception when using zookeeper
*/
class ZookeeperException : public Exception {
public:
using Exception::Exception;
};
} // cppkafka
#endif // CPPKAFKA_EXCEPTIONS_H

View File

@@ -42,10 +42,6 @@
#include "topic_partition_list.h"
#include "topic_configuration.h"
#include "configuration.h"
#include "config.h"
#ifdef CPPKAFKA_HAVE_ZOOKEEPER
#include "zookeeper/zookeeper_subscription.h"
#endif // CPPKAFKA_HAVE_ZOOKEEPER
namespace cppkafka {
@@ -180,10 +176,6 @@ private:
Configuration config_;
TopicConfigurationMap topic_configurations_;
std::mutex topic_configurations_mutex_;
#ifdef CPPKAFKA_HAVE_ZOOKEEPER
// This could be an optional but apparently move construction is only supported as of 1.56
std::unique_ptr<ZookeeperSubscription> zookeeper_subscription_;
#endif // CPPKAFKA_HAVE_ZOOKEEPER
};
} // cppkafka

View File

@@ -55,9 +55,9 @@ class TopicConfiguration;
* In order to produce messages you could do something like:
*
* \code
* // Use the zookeeper extension
* // Set the broker list
* Configuration config;
* config.set("zookeeper", "127.0.0.1:2181");
* config.set("metadata.broker.list", "127.0.0.1:9092");
*
* // Create a producer
* Producer producer(config);

View File

@@ -1,6 +0,0 @@
file(GLOB INCLUDE_FILES "*.h")
install(
FILES ${INCLUDE_FILES}
DESTINATION include/cppkafka/zookeeper
COMPONENT Headers
)

View File

@@ -1,97 +0,0 @@
/*
* Copyright (c) 2016, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef CPPKAFKA_ZOOKEEPER_POOL_H
#define CPPKAFKA_ZOOKEEPER_POOL_H
#include <map>
#include <string>
#include <chrono>
#include <mutex>
#include "zookeeper/zookeeper_watcher.h"
namespace cppkafka {
class ZookeeperSubscription;
/**
* \brief Pool of zookeeper handles
*
* This class is used internally by cppkafka.
*/
class ZookeeperPool {
public:
/**
* Get singleton instance
*/
static ZookeeperPool& instance();
/**
* Subscribe to the given endpoint
*
* \param endpoint The zookeeper endpoint to subscribe to
* \param receive_timeout The zookeeper receive timeout
* \param callback The callback to be executed on updates
*
* \return A ZookeeperSubscription that will auto-unsubscribe upon destruction
*/
ZookeeperSubscription subscribe(const std::string& endpoint,
std::chrono::milliseconds receive_timeout,
ZookeeperWatcher::WatcherCallback callback);
/**
* Unsubscribes from a previous subscription
*
* \param subscriber The subscriber return by a previous call to ZookeeperPool::subscribe
*/
void unsubscribe(const ZookeeperSubscription& subscriber);
/**
* \brief Gets the broker list for the given zookeeper endpoint
*
* Requires having previously called subscribe for this endpoint at least once.
*
* \param endpoint The endpoint for which to get the broker list
*/
std::string get_brokers(const std::string& endpoint);
/**
* Gets the amount of subscribers for the given zookeeper endpoint
*/
size_t get_subscriber_count(const std::string& endpoint) const;
private:
using WatchersMap = std::map<std::string, ZookeeperWatcher>;
WatchersMap watchers_;
mutable std::mutex watchers_mutex_;
};
} // cppkafka
#endif // CPPKAFKA_ZOOKEEPER_POOL_H

View File

@@ -1,63 +0,0 @@
/*
* Copyright (c) 2016, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef CPPKAFKA_ZOOKEEPER_SUBSCRIPTION_H
#define CPPKAFKA_ZOOKEEPER_SUBSCRIPTION_H
#include <string>
namespace cppkafka {
/**
* \cond
*/
class ZookeeperSubscription {
public:
ZookeeperSubscription(std::string endpoint, std::string subscription_id);
ZookeeperSubscription(ZookeeperSubscription&&) = default;
ZookeeperSubscription(const ZookeeperSubscription&) = delete;
ZookeeperSubscription& operator=(ZookeeperSubscription&&);
ZookeeperSubscription& operator=(const ZookeeperSubscription&) = delete;
~ZookeeperSubscription();
const std::string& get_endpoint() const;
const std::string& get_subscription_id() const;
private:
std::string endpoint_;
std::string subscription_id_;
};
/**
* \endcond
*/
} // cppkafka
#endif // CPPKAFKA_ZOOKEEPER_SUBSCRIPTION_H

View File

@@ -1,85 +0,0 @@
/*
* Copyright (c) 2016, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef CPPKAFKA_ZOOKEEPER_WATCHER_H
#define CPPKAFKA_ZOOKEEPER_WATCHER_H
#include <memory>
#include <string>
#include <chrono>
#include <map>
#include <functional>
#include <mutex>
#include <zookeeper/zookeeper.h>
namespace cppkafka {
/**
* \cond
*/
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:
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};
};
/**
* \endcond
*/
} // cppkafka
#endif // CPPKAFKA_ZOOKEEPER_WATCHER_H