Google Cloud Pub/Sub C++ Client 2.11.0
A C++ Client Library for Google Cloud Pub/Sub
No Matches
Cloud Pub/Sub C++ Client Library

Table of Contents

The Cloud Pub/Sub C++ Client library offers types and functions to use Cloud Pub/Sub from C++ applications.


The following "Hello World" program should give you a sense of how to use the library.

#include "google/cloud/pubsub/publisher.h"
#include <iostream>
int main(int argc, char* argv[]) try {
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " <project-id> <topic-id>\n";
return 1;
std::string const project_id = argv[1];
std::string const topic_id = argv[2];
// Create a namespace alias to make the code easier to read.
namespace pubsub = ::google::cloud::pubsub;
auto publisher = pubsub::Publisher(
pubsub::MakePublisherConnection(pubsub::Topic(project_id, topic_id)));
auto id =
.Publish(pubsub::MessageBuilder{}.SetData("Hello World!").Build())
if (!id) throw std::move(id).status();
std::cout << "Hello World published with id=" << *id << "\n";
return 0;
} catch (google::cloud::Status const& status) {
std::cerr << "google::cloud::Status thrown: " << status << "\n";
return 1;

More Information