Google Cloud Pub/Sub C++ Client 2.13.0
A C++ Client Library for Google Cloud Pub/Sub
|
Configure how a Subscriber
handles incoming messages.
More...
#include <google/cloud/pubsub/subscriber_options.h>
Public Member Functions | |
SubscriberOptions () | |
Initialize the subscriber options with default values. More... | |
SubscriberOptions (Options opts) | |
Initialize the subscriber options. More... | |
std::chrono::seconds | max_deadline_time () const |
The maximum deadline for each incoming message. More... | |
SubscriberOptions & | set_max_deadline_time (std::chrono::seconds d) |
Set the maximum deadline for incoming messages. More... | |
SubscriberOptions & | set_max_deadline_extension (std::chrono::seconds extension) |
Set the maximum time by which the deadline for each incoming message is extended. More... | |
std::chrono::seconds | max_deadline_extension () const |
SubscriberOptions & | set_max_outstanding_messages (std::int64_t message_count) |
Set the maximum number of outstanding messages per streaming pull. More... | |
std::int64_t | max_outstanding_messages () const |
SubscriberOptions & | set_max_outstanding_bytes (std::int64_t bytes) |
Set the maximum number of outstanding bytes per streaming pull. More... | |
std::int64_t | max_outstanding_bytes () const |
SubscriberOptions & | set_max_concurrency (std::size_t v) |
Set the maximum callback concurrency. More... | |
std::size_t | max_concurrency () const |
Maximum number of callbacks scheduled by the library at a time. More... | |
SubscriberOptions & | set_shutdown_polling_period (std::chrono::milliseconds v) |
Control how often the session polls for automatic shutdowns. More... | |
std::chrono::milliseconds | shutdown_polling_period () const |
Configure how a Subscriber
handles incoming messages.
There are two main algorithms controlled by this function: the dispatching of application callbacks, and requesting more data from the service.
The subscription configuration determines the upper limit (set set_concurrency_watermarks()
) how many callbacks are scheduled at a time. As long as this limit is not reached the library will continue to schedule callbacks, once the limit is reached the library will wait until the number of executing callbacks goes below the low watermark.
A callback is "executing" until the AckHandler::ack()
or AckHandler::nack()
function is called on the associated AckHandler
. Applications can use this to move long-running computations out of the library internal thread pool.
Note that callbacks are "scheduled", but they may not immediately execute. For example, callbacks may be sequenced if the concurrency control parameters are higher than the number of I/O threads configured in the SubscriberConnection
.
The default value for the concurrency high watermarks is set to the value returned by std::thread::hardware_concurrency()
(or 4 if your standard library returns 0
for this parameter).
The subscription will request more messages from the service as long as both the outstanding message count (see set_message_count_watermarks()
) and the number of bytes in the outstanding messages (see set_message_size_watermarks()
) are below the high watermarks for these values.
Once either of the high watermarks are breached the library will wait until both the values are below their low watermarks before requesting more messages from the service.
In this algorithm a message is outstanding until the AckHandler::ack()
or AckHandler::nack()
function is called on the associated AckHandler
. Note that if the concurrency control algorithm has not scheduled a callback this can also put back pressure on the flow control algorithm.
google::cloud::Options
and pass any subscriber options to MakeSubscriberConnection()
.google::cloud::pubsub::SubscriberOptions::SubscriberOptions | ( | ) |
Initialize the subscriber options with default values.
google::cloud::Options
instead.
|
explicit |
Initialize the subscriber options.
Expected options are any of the types in the SubscriberOptionList
GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes
in the environment and unexpected options will be logged.opts | configuration options |
google::cloud::Options
instead.
|
inline |
Maximum number of callbacks scheduled by the library at a time.
google::cloud::Options
and MaxConcurrencyOption
instead.
|
inline |
google::cloud::Options
and MaxDeadlineExtensionOption
instead.
|
inline |
The maximum deadline for each incoming message.
Configure how long does the application have to respond (ACK or NACK) an incoming message. Note that this might be longer, or shorter, than the deadline configured in the server-side subscription.
The value 0
is reserved to leave the deadline unmodified and just use the server-side configuration.
google::cloud::Options
and MaxDeadlineTimeOption
instead.
|
inline |
google::cloud::Options
and MaxOutstandingBytesOption
instead.
|
inline |
google::cloud::Options
and MaxOutstandingMessagesOption
instead. SubscriberOptions & google::cloud::pubsub::SubscriberOptions::set_max_concurrency | ( | std::size_t | v | ) |
Set 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.
v | the new value, 0 resets to the default |
google::cloud::Options
and MaxConcurrencyOption
instead. SubscriberOptions & google::cloud::pubsub::SubscriberOptions::set_max_deadline_extension | ( | std::chrono::seconds | extension | ) |
Set the maximum time by which the deadline for each incoming message is extended.
The Cloud Pub/Sub C++ client library will extend the deadline by at most this amount, while waiting for an ack or nack. The default extension is 10 minutes. An application may wish to reduce this extension so that the Pub/Sub service will resend a message sooner when it does not hear back from a Subscriber.
The value is clamped between 10 seconds and 10 minutes.
extension | the maximum time that the deadline can be extended by, measured in seconds. |
google::cloud::Options
and MaxDeadlineExtensionOption
instead.
|
inline |
Set the maximum deadline for incoming messages.
google::cloud::Options
and MaxDeadlineTimeOption
instead. SubscriberOptions & google::cloud::pubsub::SubscriberOptions::set_max_outstanding_bytes | ( | std::int64_t | bytes | ) |
Set the maximum number of outstanding bytes per streaming pull.
The Cloud Pub/Sub C++ client library uses streaming pull requests to receive messages from the service. The service will stop delivering messages if bytes
or more worth of messages have not been acknowledged nor rejected.
bytes | the maximum number of bytes outstanding, use 0 or negative numbers to make the number of bytes unlimited. |
google::cloud::Options
and MaxOutstandingBytesOption
instead. SubscriberOptions & google::cloud::pubsub::SubscriberOptions::set_max_outstanding_messages | ( | std::int64_t | message_count | ) |
Set the maximum number of outstanding messages per streaming pull.
The Cloud Pub/Sub C++ client library uses streaming pull requests to receive messages from the service. The service will stop delivering messages if message_count
or more messages have not been acknowledged nor rejected.
message_count | the maximum number of messages outstanding, use 0 or negative numbers to make the message count unlimited. |
google::cloud::Options
and MaxOutstandingMessagesOption
instead.
|
inline |
Control how often the session polls for automatic shutdowns.
Applications can shutdown a session by calling .cancel()
on the returned future<Status>
. In addition, applications can fire & forget a session, which is only shutdown once the completion queue servicing the session shuts down. In this latter case the session polls periodically to detect if the CQ has shutdown. This controls how often this polling happens.
google::cloud::Options
and ShutdownPollingPeriodOption
instead.
|
inline |
google::cloud::Options
and ShutdownPollingPeriodOption
instead.