Google Cloud Pub/Sub C++ Client 2.13.0
A C++ Client Library for Google Cloud Pub/Sub
|
Receive messages from the Cloud Pub/Sub service. More...
#include <google/cloud/pubsub/subscriber.h>
Public Member Functions | |
Subscriber (std::shared_ptr< SubscriberConnection > connection, Options opts={}) | |
future< Status > | Subscribe (ApplicationCallback cb, Options opts={}) |
Creates a new session to receive messages from subscription . More... | |
future< Status > | Subscribe (ExactlyOnceApplicationCallback cb, Options opts={}) |
Creates a new session to receive messages from subscription using exactly-once delivery. More... | |
StatusOr< PullResponse > | Pull (Options opts={}) |
Pulls one message from subscription . More... | |
Receive messages from the Cloud Pub/Sub service.
This class is used to receive message from a given subscription, with a fixed configuration such as credentials, and background threads. Applications that receive messages from multiple subscriptions need to create separate instances of this class. Applications wanting to receive events with configuration parameters also need to create separate instances.
Subscriber
objects are relatively cheap to create, copy, and move. However, each Subscriber
object must be created with a std::shared_ptr<SubscriberConnection>
, which itself is relatively expensive to create. Therefore, connection instances should be shared when possible. See the MakeSubscriberConnection()
function and the SubscriberConnection
interface for more details.Options
from GrpcOptionList
. Applications can create their own pool of background threads by (a) creating their own google::cloud::CompletionQueue, (b) passing this completion queue as a GrpcCompletionQueueOption
, and (c) attaching any number of threads to the completion queue.future<T>
(or future<StatusOr<T>>
) object. Readers are probably familiar with std::future<T>
. Our version adds a .then()
function to attach a callback to the future, which is invoked when the future is satisfied. This function returns a future<U>
where U
is the return value of the attached function. More details in the google::cloud::future documentation.StatusOr<T>
to report errors. When an operation fails to perform its work the returned StatusOr<T>
contains the error details. If the ok()
member function in the StatusOr<T>
returns true
then it contains the expected result. Please consult the google::cloud::StatusOr documentation for more details.
|
explicit |
StatusOr< PullResponse > google::cloud::pubsub::Subscriber::Pull | ( | Options | opts = {} | ) |
Pulls one message from subscription
.
This is an idempotent operation; it only reads messages from the service. It will make multiple attempts to pull a message from the service, subject to the retry policies configured in the SubscriberConnection
.
Note that calling PullAckHandler::ack()
and/or PullAckHandler::nack()
have their own rules with respect to retrying.
opts | any option overrides to use in this call. These options take precedence over the options passed in the constructor, and over any options provided in the PublisherConnection initialization. |
PullAckHandler
to notify the library when the message has been successfully handled. future< Status > google::cloud::pubsub::Subscriber::Subscribe | ( | ApplicationCallback | cb, |
Options | opts = {} |
||
) |
Creates a new session to receive messages from subscription
.
This is an idempotent operation; it only reads messages from the service. Will make multiple attempts to start a connection to the service, subject to the retry policies configured in the SubscriberConnection
. Once a successful connection is established the library will try to resume the connection even if the connection fails with a permanent error. Resuming the connection is subject to the retry policies as described earlier.
Note that calling AckHandler::ack()
and/or AckHandler::nack()
is handled differently with respect to retrying. Check the documentation of these functions for details.
cb | the callable invoked when messages are received. |
opts | any option overrides to use in this call. These options take precedence over the options passed in the constructor, and over any options provided in the PublisherConnection initialization. |
.cancel()
in this object will (eventually) terminate the session and satisfy the future. future< Status > google::cloud::pubsub::Subscriber::Subscribe | ( | ExactlyOnceApplicationCallback | cb, |
Options | opts = {} |
||
) |
Creates a new session to receive messages from subscription
using exactly-once delivery.
This is an idempotent operation; it only reads messages from the service. Will make multiple attempts to start a connection to the service, subject to the retry policies configured in the SubscriberConnection
. Once a successful connection is established the library will try to resume the connection even if the connection fails with a permanent error. Resuming the connection is subject to the retry policies as described earlier.
Note that calling ExactlyOnceAckHandler::ack()
and/or ExactlyOnceAckHandler::nack()
have their own rules with respect to retrying. Check the documentation of these functions for details.
cb | the callable invoked when messages are received. |
opts | any option overrides to use in this call. These options take precedence over the options passed in the constructor, and over any options provided in the PublisherConnection initialization. |
.cancel()
in this object will (eventually) terminate the session and satisfy the future.