Google Cloud Pub/Sub C++ Client  1.32.1
A C++ Client Library for Google Cloud Pub/Sub
Public Types | List of all members
google::cloud::pubsub::v1::MaxConcurrencyOption Struct Reference

The maximum callback concurrency. More...

#include <google/cloud/pubsub/options.h>

Public Types

using Type = std::size_t
 

Detailed Description

The maximum callback concurrency.

The Cloud Pub/Sub C++ client library will schedule parallel callbacks as long as the number of outstanding callbacks is less than this maximum.

Note that this controls the number of callbacks scheduled, not the number of callbacks actually executing at a time. The application needs to create (or configure) the background threads pool with enough parallelism to execute more than one callback at a time.

Some applications may want to share a thread pool across many subscriptions. The additional level of control (scheduled vs. running callbacks) allows applications, for example, to ensure that at most K threads in the pool are used by any given subscription.

Example
namespace pubsub = ::google::cloud::pubsub;
using ::google::cloud::future;
using ::google::cloud::GrpcBackgroundThreadPoolSizeOption;
using ::google::cloud::Options;
using ::google::cloud::StatusOr;
auto sample = [](std::string project_id, std::string subscription_id) {
// Create a subscriber with 16 threads handling I/O work, by default the
// library creates `std::thread::hardware_concurrency()` threads.
pubsub::Subscription(std::move(project_id), std::move(subscription_id)),
Options{}
.set<GrpcBackgroundThreadPoolSizeOption>(16)));
// Create a subscription where up to 8 messages are handled concurrently. By
// default the library uses `std::thread::hardware_concurrency()` as the
// maximum number of concurrent callbacks.
auto session = subscriber.Subscribe(
// This handler executes in the I/O threads, applications could use,
// std::async(), a thread-pool, or any other mechanism to transfer the
// execution to other threads.
std::cout << "Received message " << m << "\n";
std::move(h).ack();
PleaseIgnoreThisSimplifiesTestingTheSamples();
});
return std::make_pair(subscriber, std::move(session));
};
Defines the interface to acknowledge and reject messages.
Definition: ack_handler.h:48
The C++ representation for a Cloud Pub/Sub messages.
Definition: message.h:78
Receive messages from the Cloud Pub/Sub service.
Definition: subscriber.h:89
future< Status > Subscribe(Callable &&cb)
Creates a new session to receive messages from subscription.
Definition: subscriber.h:129
Objects of this class identify a Cloud Pub/Sub subscription.
Definition: subscription.h:37
std::shared_ptr< SubscriberConnection > MakeSubscriberConnection(Subscription subscription, std::initializer_list< pubsub_internal::NonConstructible >)
Creates a new SubscriberConnection object to work with Subscriber.
Contains all the Cloud Pubsub C++ client types and functions.
Definition: ack_handler.cc:20
The maximum callback concurrency.
Definition: options.h:264

Definition at line 264 of file options.h.

Member Typedef Documentation

◆ Type

Definition at line 265 of file options.h.