@@ -18,20 +18,24 @@ using cppkafka::Configuration;
1818using cppkafka::Topic;
1919using cppkafka::GroupInformation;
2020using cppkafka::GroupMemberInformation;
21+ using cppkafka::MemberAssignmentInformation;
2122
2223namespace po = boost::program_options;
2324
2425int main (int argc, char * argv[]) {
2526 string brokers;
2627 string group_id;
28+ bool show_assignment = false ;
2729
2830 po::options_description options (" Options" );
2931 options.add_options ()
30- (" help,h" , " produce this help message" )
31- (" brokers,b" , po::value<string>(&brokers)->required (),
32- " the kafka broker list" )
33- (" group-id,g" , po::value<string>(&group_id),
34- " only fetch consumer group information for the specified one" )
32+ (" help,h" , " produce this help message" )
33+ (" brokers,b" , po::value<string>(&brokers)->required (),
34+ " the kafka broker list" )
35+ (" group-id,g" , po::value<string>(&group_id),
36+ " only fetch consumer group information for the specified one" )
37+ (" assignment,a" , po::value<bool >(&show_assignment)->implicit_value (true ),
38+ " show topic/partition assignment for each consumer group" )
3539 ;
3640
3741 po::variables_map vm;
@@ -74,9 +78,15 @@ int main(int argc, char* argv[]) {
7478 }
7579 cout << " Found the following consumers: " << endl;
7680 for (const GroupInformation& group : groups) {
77- cout << " * \" " << group.get_name () << " \" having the following members: " << endl;
81+ cout << " * \" " << group.get_name () << " \" having the following (" <<
82+ group.get_members ().size () << " ) members: " << endl;
7883 for (const GroupMemberInformation& info : group.get_members ()) {
79- cout << " - " << info.get_member_id () << " @ " << info.get_client_host () << endl;
84+ cout << " - " << info.get_member_id () << " @ " << info.get_client_host ();
85+ if (show_assignment) {
86+ MemberAssignmentInformation assignment (info.get_member_assignment ());
87+ cout << " has assigned: " << assignment.get_topic_partitions ();
88+ }
89+ cout << endl;
8090 }
8191 cout << endl;
8292 }
0 commit comments