MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/cpp-samples / main

Function main

pubsub-open-telemetry/blocking_publisher.cc:60–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58} // namespace
59
60int main(int argc, char* argv[]) try {
61 auto args = ParseArguments(argc, argv);
62 if (args.project_id.empty() && args.topic_id.empty()) {
63 return 1;
64 }
65 std::cout << "Using project `" << args.project_id << "` and topic `"
66 << args.topic_id << "`\n";
67
68 // Automatically call `Cleanup()` before returning from `main()`.
69 std::shared_ptr<void> cleanup(nullptr, [](void*) { Cleanup(); });
70
71 ConfigureCloudTraceTracer(args);
72
73 auto blocking_publisher = pubsub::BlockingPublisher(
74 pubsub::MakeBlockingPublisherConnection(args.publisher_options));
75
76 auto id = blocking_publisher.Publish(
77 pubsub::Topic(args.project_id, args.topic_id),
78 pubsub::MessageBuilder().SetData("Hello!").Build());
79
80 if (!id) throw std::move(id).status();
81 std::cout << "Sent message with id: " << *id << "\n";
82
83 return 0;
84} catch (google::cloud::Status const& status) {
85 std::cerr << "google::cloud::Status thrown: " << status << "\n";
86 return 1;
87}

Callers

nothing calls this directly

Calls 3

ParseArgumentsFunction · 0.70
CleanupFunction · 0.70

Tested by

no test coverage detected