Error Handlingto learn how the library reports run-time errors.
Environment Variablesfor environment variables affecting the library. Some of these environment variables enable logging to the console. This can be an effective approach to diagnose runtime problems.
TheSetting up your development environmentguide describes how to set up a C++ development environment in various platforms, including the Google Cloud C++ client libraries.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThis webpage provides documentation for the Cloud Pub/Sub C++ Client Library, which allows C++ applications to interact with Cloud Pub/Sub services.\u003c/p\u003e\n"],["\u003cp\u003eThe library includes functions for efficiently publishing messages using \u003ccode\u003ePublisher::Publish()\u003c/code\u003e and \u003ccode\u003eBlockingPublisher::Publish()\u003c/code\u003e, and receiving messages either asynchronously with \u003ccode\u003eSubscriber::Subscribe()\u003c/code\u003e or by pulling a single message with \u003ccode\u003eSubscriber::Pull()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe documentation offers a quickstart guide with a "Hello World" program example to demonstrate basic library usage, and provides comprehensive information on error handling and environment variables that affect the library.\u003c/p\u003e\n"],["\u003cp\u003eThe library can be configured by overriding the default endpoint and authentication configuration, as well as the retry, backoff and idempotency policies, allowing for flexibility.\u003c/p\u003e\n"],["\u003cp\u003eThe site also details how to test Pub/Sub applications using \u003ccode\u003egooglemock\u003c/code\u003e to mock \u003ccode\u003ePublisher\u003c/code\u003e and \u003ccode\u003eSubscriber\u003c/code\u003e objects, along with a guide on setting up the C++ development environment.\u003c/p\u003e\n"]]],[],null,["Version 2.19.0keyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/pubsub/latest)\n- [2.41.0](/cpp/docs/reference/pubsub/2.41.0)\n- [2.40.0](/cpp/docs/reference/pubsub/2.40.0)\n- [2.39.0](/cpp/docs/reference/pubsub/2.39.0)\n- [2.38.0](/cpp/docs/reference/pubsub/2.38.0)\n- [2.37.0](/cpp/docs/reference/pubsub/2.37.0)\n- [2.36.0](/cpp/docs/reference/pubsub/2.36.0)\n- [2.35.0](/cpp/docs/reference/pubsub/2.35.0)\n- [2.34.0](/cpp/docs/reference/pubsub/2.34.0)\n- [2.33.0](/cpp/docs/reference/pubsub/2.33.0)\n- [2.32.0](/cpp/docs/reference/pubsub/2.32.0)\n- [2.31.0](/cpp/docs/reference/pubsub/2.31.0)\n- [2.30.0](/cpp/docs/reference/pubsub/2.30.0)\n- [2.29.0](/cpp/docs/reference/pubsub/2.29.0)\n- [2.28.0](/cpp/docs/reference/pubsub/2.28.0)\n- [2.27.0](/cpp/docs/reference/pubsub/2.27.0)\n- [2.26.0](/cpp/docs/reference/pubsub/2.26.0)\n- [2.25.1](/cpp/docs/reference/pubsub/2.25.1)\n- [2.24.0](/cpp/docs/reference/pubsub/2.24.0)\n- [2.23.0](/cpp/docs/reference/pubsub/2.23.0)\n- [2.22.1](/cpp/docs/reference/pubsub/2.22.1)\n- [2.21.0](/cpp/docs/reference/pubsub/2.21.0)\n- [2.20.0](/cpp/docs/reference/pubsub/2.20.0)\n- [2.19.0](/cpp/docs/reference/pubsub/2.19.0)\n- [2.18.0](/cpp/docs/reference/pubsub/2.18.0)\n- [2.17.0](/cpp/docs/reference/pubsub/2.17.0)\n- [2.16.0](/cpp/docs/reference/pubsub/2.16.0)\n- [2.15.1](/cpp/docs/reference/pubsub/2.15.1)\n- [2.14.0](/cpp/docs/reference/pubsub/2.14.0)\n- [2.13.0](/cpp/docs/reference/pubsub/2.13.0)\n- [2.12.0](/cpp/docs/reference/pubsub/2.12.0)\n- [2.11.0](/cpp/docs/reference/pubsub/2.11.0) \n\nCloud Pub/Sub C++ Client Library\n================================\n\nThe Cloud Pub/Sub C++ Client library offers types and functions to use Cloud Pub/Sub from C++ applications.\n\n### Quickstart\n\nThe following \"Hello World\" program should give you a sense of how to use the library. \n\n #include \"google/cloud/pubsub/publisher.h\"\n #include \u003ciostream\u003e\n\n int main(int argc, char* argv[]) try {\n if (argc != 3) {\n std::cerr \u003c\u003c \"Usage: \" \u003c\u003c argv[0] \u003c\u003c \" \u003cproject-id\u003e \u003ctopic-id\u003e\\n\";\n return 1;\n }\n\n std::string const project_id = argv[1];\n std::string const topic_id = argv[2];\n\n // Create a namespace alias to make the code easier to read.\n namespace pubsub = ::google::cloud::pubsub;\n\n auto publisher = pubsub::Publisher(\n pubsub::MakePublisherConnection(pubsub::Topic(project_id, topic_id)));\n auto id =\n publisher\n .Publish(pubsub::MessageBuilder{}.SetData(\"Hello World!\").Build())\n .get();\n if (!id) throw std::move(id).status();\n std::cout \u003c\u003c \"Hello World published with id=\" \u003c\u003c *id \u003c\u003c \"\\n\";\n\n return 0;\n } catch (google::cloud::Status const& status) {\n std::cerr \u003c\u003c \"google::cloud::Status thrown: \" \u003c\u003c status \u003c\u003c \"\\n\";\n return 1;\n }\n\n### More Information\n\n- [`Publisher::Publish()`](/cpp/docs/reference/pubsub/2.19.0/classgoogle_1_1cloud_1_1pubsub_1_1Publisher#classgoogle_1_1cloud_1_1pubsub_1_1Publisher_1adcaba4f8339e31d6d296eab026164a4a) - to efficiently publish Pub/Sub messages.\n- [`BlockingPublisher::Publish()`](/cpp/docs/reference/pubsub/2.19.0/classgoogle_1_1cloud_1_1pubsub_1_1BlockingPublisher#classgoogle_1_1cloud_1_1pubsub_1_1BlockingPublisher_1a37e3aae927a3fb1fa2e83f1663d621a1) - to publish a single Pub/Sub messages.\n- [`Subscriber::Subscribe()`](/cpp/docs/reference/pubsub/2.19.0/classgoogle_1_1cloud_1_1pubsub_1_1Subscriber#classgoogle_1_1cloud_1_1pubsub_1_1Subscriber_1a5d9951d7bb77a77943712dc788498977) - to asynchronous receive Pub/Sub messages.\n- [`Subscriber::Pull()`](/cpp/docs/reference/pubsub/2.19.0/classgoogle_1_1cloud_1_1pubsub_1_1Subscriber#classgoogle_1_1cloud_1_1pubsub_1_1Subscriber_1ad0707c03975538e0b2ec564cfd6ee17e) - to receive a single Pub/Sub messages.\n- [Error Handling](/cpp/docs/reference/pubsub/2.19.0/pubsub-error-handling) to learn how the library reports run-time errors.\n- [Environment Variables](/cpp/docs/reference/pubsub/2.19.0/pubsub-env) for environment variables affecting the library. Some of these environment variables enable logging to the console. This can be an effective approach to diagnose runtime problems.\n- [Override the default endpoint](/cpp/docs/reference/pubsub/2.19.0/pubsub-endpoint-example)\n- [Override the authentication configuration](/cpp/docs/reference/pubsub/2.19.0/pubsub-auth-example)\n- [Override Retry, Backoff, and Idempotency Policies](/cpp/docs/reference/pubsub/2.19.0/pubsub-override-retry)\n- [Testing your Cloud Pub/Sub publisher application with googlemock](/cpp/docs/reference/pubsub/2.19.0/publisher-mock) shows how to write tests mocking [Publisher](/cpp/docs/reference/pubsub/2.19.0/classgoogle_1_1cloud_1_1pubsub_1_1Publisher)\n- [Testing your Cloud Pub/Sub subscriber application with googlemock](/cpp/docs/reference/pubsub/2.19.0/subscriber-mock) shows how to write tests mocking [Subscriber](/cpp/docs/reference/pubsub/2.19.0/classgoogle_1_1cloud_1_1pubsub_1_1Subscriber)\n- The [Setting up your development environment](https://cloud.google.com/cpp/docs/setup) guide describes how to set up a C++ development environment in various platforms, including the Google Cloud C++ client libraries."]]