-
Notifications
You must be signed in to change notification settings - Fork 206
Fetching metadata
Matias Fontanini edited this page Jun 4, 2017
·
1 revision
Fetching topic/broker metadata can be done via Consumer/Producer::get_metadata
. This will return a Metadata
object that contains all the information:
// Create a consumer
Consumer consumer(...);
// Fetch all metadata
Metadata metadata = consumer.get_metadata();
cout << "Found " << metadata.get_brokers().size() << " brokers" << endl;
cout << "Found " << metadata.get_topics().size() << " topics" << endl;
If you only want to fetch the metadata for a single topic, you can use the overload that takes a Topic
object:
// Get the topic object
const Topic topic = consumer.get_topic("some_topic");
// Fetch a specific topic's metadata
TopicMetadata metadata = consumer.get_metadata(topic);
cout << "The topic has " << metadata.get_partitions().size() << " topics" << endl;