66
77int main (int argc, char **argv)
88{
9+ using namespace kafka ;
910 using namespace kafka ::clients;
11+ using namespace kafka ::clients::producer;
1012
1113 if (argc != 3 ) {
1214 std::cerr << " Usage: " << argv[0 ] << " <brokers> <topic>\n " ;
1315 exit (argc == 1 ? 0 : 1 ); // NOLINT
1416 }
1517
1618 const std::string brokers = argv[1 ];
17- const kafka:: Topic topic = argv[2 ];
19+ const Topic topic = argv[2 ];
1820
1921 try {
2022
2123 // Create configuration object
22- const kafka:: Properties props ({
23- {" bootstrap.servers" , brokers},
24- {" enable.idempotence" , " true" },
24+ const Properties props ({
25+ {" bootstrap.servers" , { brokers} },
26+ {" enable.idempotence" , { " true" } },
2527 });
2628
2729 // Create a producer instance
@@ -34,17 +36,17 @@ int main(int argc, char **argv)
3436 std::getline (std::cin, *line);
3537 line = std::make_shared<std::string>()) {
3638 // The ProducerRecord doesn't own `line`, it is just a thin wrapper
37- auto record = producer:: ProducerRecord (topic,
38- kafka:: NullKey,
39- kafka:: Value (line->c_str (), line->size ()));
39+ auto record = ProducerRecord (topic,
40+ NullKey,
41+ Value (line->c_str (), line->size ()));
4042
4143 // Send the message
4244 producer.send (record,
4345 // The delivery report handler
4446 // Note: Here we capture the shared_pointer of `line`,
4547 // which holds the content for `record.value()`.
4648 // It makes sure the memory block is valid until the lambda finishes.
47- [line](const producer:: RecordMetadata& metadata, const kafka:: Error& error) {
49+ [line](const RecordMetadata& metadata, const Error& error) {
4850 if (!error) {
4951 std::cout << " % Message delivered: " << metadata.toString () << std::endl;
5052 } else {
@@ -57,7 +59,7 @@ int main(int argc, char **argv)
5759
5860 // producer.close(); // No explicit close is needed, RAII will take care of it
5961
60- } catch (const kafka:: KafkaException& e) {
62+ } catch (const KafkaException& e) {
6163 std::cerr << " % Unexpected exception caught: " << e.what () << std::endl;
6264 }
6365}
0 commit comments