/* * 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_CONFIGURATION_H #define CPPKAFKA_CONFIGURATION_H #include #include #include #include #include #include #include #include #include "topic_partition_list.h" #include "topic_configuration.h" #include "clonable_ptr.h" #include "configuration_base.h" namespace cppkafka { class Message; class Producer; class Consumer; class KafkaHandleBase; class Configuration : public ConfigurationBase { public: using DeliveryReportCallback = std::function; using OffsetCommitCallback = std::function; using ErrorCallback = std::function; using ThrottleCallback = std::function; using LogCallback = std::function; using StatsCallback = std::function; using SocketCallback = std::function; using ConfigurationBase::set; Configuration(); void set(const std::string& name, const std::string& value); void set_delivery_report_callback(DeliveryReportCallback callback); void set_offset_commit_callback(OffsetCommitCallback callback); void set_error_callback(ErrorCallback callback); void set_throttle_callback(ThrottleCallback callback); void set_log_callback(LogCallback callback); void set_stats_callback(StatsCallback callback); void set_socket_callback(SocketCallback callback); void set_default_topic_configuration(boost::optional config); bool has_property(const std::string& name) const; rd_kafka_conf_t* get_handle() const; std::string get(const std::string& name) const; const DeliveryReportCallback& get_delivery_report_callback() const; const OffsetCommitCallback& get_offset_commit_callback() const; const ErrorCallback& get_error_callback() const; const ThrottleCallback& get_throttle_callback() const; const LogCallback& get_log_callback() const; const StatsCallback& get_stats_callback() const; const SocketCallback& get_socket_callback() const; const boost::optional& get_default_topic_configuration() const; boost::optional& get_default_topic_configuration(); private: static const std::unordered_set VALID_EXTENSIONS; using HandlePtr = ClonablePtr; using PropertiesMap = std::unordered_map; Configuration(rd_kafka_conf_t* ptr); static HandlePtr make_handle(rd_kafka_conf_t* ptr); HandlePtr handle_; boost::optional default_topic_config_; DeliveryReportCallback delivery_report_callback_; OffsetCommitCallback offset_commit_callback_; ErrorCallback error_callback_; ThrottleCallback throttle_callback_; LogCallback log_callback_; StatsCallback stats_callback_; SocketCallback socket_callback_; PropertiesMap extension_properties_; }; } // cppkafka #endif // CPPKAFKA_CONFIGURATION_H