mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka.git
synced 2025-11-03 12:07:57 +00:00
Use Producer rather than Consumer in metadata example
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
#include "cppkafka/consumer.h"
|
#include "cppkafka/producer.h"
|
||||||
#include "cppkafka/configuration.h"
|
#include "cppkafka/configuration.h"
|
||||||
#include "cppkafka/metadata.h"
|
#include "cppkafka/metadata.h"
|
||||||
#include "cppkafka/topic.h"
|
#include "cppkafka/topic.h"
|
||||||
@@ -12,7 +12,7 @@ using std::exception;
|
|||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
|
|
||||||
using cppkafka::Consumer;
|
using cppkafka::Producer;
|
||||||
using cppkafka::Exception;
|
using cppkafka::Exception;
|
||||||
using cppkafka::Configuration;
|
using cppkafka::Configuration;
|
||||||
using cppkafka::Topic;
|
using cppkafka::Topic;
|
||||||
@@ -33,8 +33,6 @@ int main(int argc, char* argv[]) {
|
|||||||
("help,h", "produce this help message")
|
("help,h", "produce this help message")
|
||||||
("brokers,b", po::value<string>(&brokers)->required(),
|
("brokers,b", po::value<string>(&brokers)->required(),
|
||||||
"the kafka broker list")
|
"the kafka broker list")
|
||||||
("group-id,g", po::value<string>(&group_id)->required(),
|
|
||||||
"the consumer group id")
|
|
||||||
;
|
;
|
||||||
|
|
||||||
po::variables_map vm;
|
po::variables_map vm;
|
||||||
@@ -56,17 +54,16 @@ int main(int argc, char* argv[]) {
|
|||||||
// Construct the configuration
|
// Construct the configuration
|
||||||
Configuration config = {
|
Configuration config = {
|
||||||
{ "metadata.broker.list", brokers },
|
{ "metadata.broker.list", brokers },
|
||||||
{ "group.id", group_id },
|
|
||||||
// Disable auto commit
|
// Disable auto commit
|
||||||
{ "enable.auto.commit", false }
|
{ "enable.auto.commit", false }
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Construct a consumer
|
// Construct a producer
|
||||||
Consumer consumer(config);
|
Producer producer(config);
|
||||||
|
|
||||||
// Fetch the metadata
|
// Fetch the metadata
|
||||||
Metadata metadata = consumer.get_metadata();
|
Metadata metadata = producer.get_metadata();
|
||||||
|
|
||||||
// Iterate over brokers
|
// Iterate over brokers
|
||||||
cout << "Found the following brokers: " << endl;
|
cout << "Found the following brokers: " << endl;
|
||||||
|
|||||||
Reference in New Issue
Block a user