Skip to content

Commit

Permalink
Add missing sample and fix references
Browse files Browse the repository at this point in the history
  • Loading branch information
coryan committed Oct 17, 2022
1 parent 641f873 commit a4765c5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions google/cloud/pubsub/blocking_publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ class BlockingPublisher {
* by changing the retry policy, please see the example below.
*
* @par Example
* @snippet samples.cc blocking-publish
* @snippet blocking_samples.cc blocking-publish
*
* @par Example
* @snippet samples.cc blocking-publish-no-retry
* @snippet blocking_samples.cc blocking-publish-no-retry
*
* @return On success, the server-assigned ID of the message. IDs are
* guaranteed to be unique within the topic.
Expand Down
25 changes: 25 additions & 0 deletions google/cloud/pubsub/samples/blocking_samples.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,30 @@ void BlockingPublish(std::vector<std::string> const& argv) {
(argv.at(0), argv.at(1));
}

void BlockingPublishNoRetry(std::vector<std::string> const& argv) {
namespace examples = ::google::cloud::testing_util;
if (argv.size() != 2) {
throw examples::Usage{"blocking-publish-no-retry <project-id> <topic-id>"};
}
//! [blocking-publish-no-retry]
namespace pubsub = ::google::cloud::pubsub;
[](std::string project_id, std::string topic_id) {
auto topic = pubsub::Topic(std::move(project_id), std::move(topic_id));
auto publisher =
pubsub::BlockingPublisher(pubsub::MakeBlockingPublisherConnection());
auto id = publisher.Publish(
topic, pubsub::MessageBuilder().SetData("Hello World!").Build(),
google::cloud::Options{}.set<pubsub::RetryPolicyOption>(
pubsub::LimitedErrorCountRetryPolicy(/*maximum_failures=*/0)
.clone()));
if (!id) return; // Without retries, errors are likely.
std::cout << "Hello World successfully published on topic "
<< topic.FullName() << " with id " << *id << "\n";
}
//! [blocking-publish-no-retry]
(argv.at(0), argv.at(1));
}

void AutoRun(std::vector<std::string> const& argv) {
namespace examples = ::google::cloud::testing_util;

Expand Down Expand Up @@ -81,6 +105,7 @@ int main(int argc, char* argv[]) { // NOLINT(bugprone-exception-escape)

Example example({
{"blocking-publish", BlockingPublish},
{"blocking-publish-no-retry", BlockingPublishNoRetry},
{"auto", AutoRun},
});
return example.Run(argc, argv);
Expand Down

0 comments on commit a4765c5

Please sign in to comment.