Allow getting consumer group information

This commit is contained in:
Matias Fontanini
2017-04-16 19:45:03 -07:00
parent ebde747e18
commit dbb547889b
15 changed files with 544 additions and 116 deletions

View File

@@ -74,6 +74,30 @@ public:
InvalidConfigOptionType(const std::string& config_name, const std::string& type);
};
/**
* Indicates something that was being looked up failed to be found
*/
class CPPKAFKA_API ElementNotFound : public Exception {
public:
ElementNotFound(const std::string& element_type, const std::string& name);
};
/**
* Indicates something that was incorrectly parsed
*/
class CPPKAFKA_API ParseException : public Exception {
public:
ParseException(const std::string& message);
};
/**
* Indicates something had an unexpected versiom
*/
class CPPKAFKA_API UnexpectedVersion : public Exception {
public:
UnexpectedVersion(uint32_t version);
};
/**
* A generic rdkafka handle error
*/

View File

@@ -0,0 +1,141 @@
#ifndef CPPKAFKA_GROUP_INFORMATION_H
#define CPPKAFKA_GROUP_INFORMATION_H
#include <vector>
#include <cstdint>
#include "macros.h"
#include "metadata.h"
#include "error.h"
#include "topic_partition_list.h"
namespace cppkafka {
/**
* \brief Parses the member assignment information
*
* This class parses the data in GroupMemberInformation::get_member_assignment.
*/
class CPPKAFKA_API MemberAssignmentInformation {
public:
/**
* Constructs an instance
*/
MemberAssignmentInformation(const std::vector<uint8_t>& data);
/**
* Gets the version
*/
uint16_t get_version() const;
/**
* Gets the topic/partition assignment
*/
const TopicPartitionList& get_topic_partitions() const;
private:
uint16_t version_;
TopicPartitionList topic_partitions_;
};
/**
* \brief Represents the information about a specific consumer group member
*/
class CPPKAFKA_API GroupMemberInformation {
public:
/**
* Constructs an instance using the provided information
*
* \param info The information pointer
*/
GroupMemberInformation(const rd_kafka_group_member_info& info);
/**
* Gets the member id
*/
const std::string& get_member_id() const;
/**
* Gets the client id
*/
const std::string& get_client_id() const;
/**
* Gets the client host
*/
const std::string& get_client_host() const;
/**
* Gets the member metadata
*/
const std::vector<uint8_t>& get_member_metadata() const;
/**
* Gets the member assignment
*/
const std::vector<uint8_t>& get_member_assignment() const;
private:
std::string member_id_;
std::string client_id_;
std::string client_host_;
std::vector<uint8_t> member_metadata_;
std::vector<uint8_t> member_assignment_;
};
/**
* \brief Represents the information about a specific consumer group
*/
class CPPKAFKA_API GroupInformation {
public:
/**
* Constructs an instance using the provided information.
*
* \param info The information pointer
*/
GroupInformation(const rd_kafka_group_info& info);
/**
* Gets the broker metadata
*/
const BrokerMetadata& get_broker() const;
/**
* Gets the group name
*/
const std::string& get_name() const;
/**
* Gets the broker-originated error
*/
Error get_error() const;
/**
* Gets the group state
*/
const std::string& get_state() const;
/**
* Gets the group protocol type
*/
const std::string& get_protocol_type() const;
/**
* Gets the group protocol
*/
const std::string& get_protocol() const;
/**
* Gets the group members
*/
const std::vector<GroupMemberInformation>& get_members() const;
private:
BrokerMetadata broker_;
std::string name_;
Error error_;
std::string state_;
std::string protocol_type_;
std::string protocol_;
std::vector<GroupMemberInformation> members_;
};
} // cppkafka
#endif // CPPKAFKA_GROUP_INFORMATION_H

View File

@@ -50,6 +50,7 @@ namespace cppkafka {
class Topic;
class Metadata;
class TopicMetadata;
class GroupInformation;
/**
* Base class for kafka consumer/producer
@@ -155,6 +156,18 @@ public:
*/
TopicMetadata get_metadata(const Topic& topic) const;
/**
* Gets the consumer group information
*
* \param name The name of the consumer group to look up
*/
GroupInformation get_consumer_group(const std::string& name);
/**
* Gets all consumer groups
*/
std::vector<GroupInformation> get_consumer_groups();
/**
* \brief Gets topic/partition offsets based on timestamps
*
@@ -201,6 +214,7 @@ private:
Topic get_topic(const std::string& name, rd_kafka_topic_conf_t* conf);
Metadata get_metadata(bool all_topics, rd_kafka_topic_t* topic_ptr) const;
std::vector<GroupInformation> fetch_consumer_groups(const char* name);
void save_topic_config(const std::string& topic_name, TopicConfiguration config);
HandlePtr handle_;

View File

@@ -117,6 +117,16 @@ public:
*/
bool operator<(const TopicPartition& rhs) const;
/**
* Compare the (topic, partition) for equality
*/
bool operator==(const TopicPartition& rhs) const;
/**
* Compare the (topic, partition) for in-equality
*/
bool operator!=(const TopicPartition& rhs) const;
/**
* Print to a stream
*/