Google Cloud Pub/Sub C++ Client  1.31.1
A C++ Client Library for Google Cloud Pub/Sub
Classes | Typedefs | Functions
google::cloud::pubsub::v1 Namespace Reference

The inlined, versioned namespace for the Cloud Pubsub C++ client APIs. More...

Classes

class  AckHandler
 Defines the interface to acknowledge and reject messages. More...
 
class  Publisher
 Publish messages to the Cloud Pub/Sub service. More...
 
class  Subscriber
 Receive messages from the Cloud Pub/Sub service. More...
 
class  SubscriptionAdminClient
 Performs subscription administrative operations in Cloud Pub/Sub. More...
 
class  TopicAdminClient
 Performs topic admin operations in Cloud Pub/Sub. More...
 
struct  ConnectionOptionsTraits
 The Cloud Pub/Sub connection traits. More...
 
class  PublisherConnection
 A connection to the Cloud Pub/Sub service to publish events. More...
 
class  PublisherOptions
 Configuration options for a Publisher. More...
 
class  Message
 The C++ representation for a Cloud Pub/Sub messages. More...
 
class  MessageBuilder
 Constructs Message objects. More...
 
class  SubscriberConnection
 A connection to the Cloud Pub/Sub service to receive events. More...
 
class  Subscription
 Objects of this class identify a Cloud Pub/Sub subscription. More...
 
class  SnapshotBuilder
 Build a request to create a Cloud Pub/Sub snapshot. More...
 
class  SubscriptionAdminConnection
 A connection to Cloud Pub/Sub for subscription-related administrative operations. More...
 
class  PushConfigBuilder
 Helper class to create google::pubsub::v1::PushConfig protos. More...
 
class  SubscriptionBuilder
 Create a Cloud Pub/Sub subscription configuration. More...
 
class  Snapshot
 Objects of this class identify a Cloud Pub/Sub snapshot. More...
 
class  TopicAdminConnection
 A connection to Cloud Pub/Sub for topic-related administrative operations. More...
 
class  TopicBuilder
 Builds requests to create or update a Cloud Pub/Sub topic. More...
 
class  SubscriberOptions
 Configure how a Subscriber handles incoming messages. More...
 
class  Topic
 Objects of this class identify a Cloud Pub/Sub topic. More...
 
class  SchemaAdminClient
 Performs schema admin operations in Cloud Pub/Sub. More...
 
class  Schema
 Objects of this class identify a Cloud Pub/Sub schema. More...
 
class  SchemaAdminConnection
 A connection to Cloud Pub/Sub for schema-related administrative operations. More...
 
class  MockSchemaAdminConnection
 A googlemock-based mock for [pubsub::SchemaAdminConnection][mocked-link]. More...
 

Typedefs

using ConnectionOptions = ::google::cloud::ConnectionOptions< ConnectionOptionsTraits >
 Configure a connection for Cloud Pub/Sub services. More...
 
using PubsubMessageDataType = std::decay< decltype(std::declval< google::pubsub::v1::PubsubMessage >().data())>::type
 Defines the type for message data. More...
 
using ListSubscriptionsRange = google::cloud::internal::PaginationRange< google::pubsub::v1::Subscription >
 An input range to stream Cloud Pub/Sub subscriptions. More...
 
using ListSnapshotsRange = google::cloud::internal::PaginationRange< google::pubsub::v1::Snapshot >
 An input range to stream Cloud Pub/Sub snapshots. More...
 
using ListTopicsRange = google::cloud::internal::PaginationRange< google::pubsub::v1::Topic >
 An input range to stream Cloud Pub/Sub topics. More...
 
using ListTopicSubscriptionsRange = google::cloud::internal::PaginationRange< std::string >
 An input range to stream the Cloud Pub/Sub subscriptions of a topic. More...
 
using ListTopicSnapshotsRange = google::cloud::internal::PaginationRange< std::string >
 An input range to stream the Cloud Pub/Sub snapshots of a topic. More...
 
using BackoffPolicy = ::google::cloud::internal::BackoffPolicy
 The base class for backoff policies. More...
 
using ExponentialBackoffPolicy = google::cloud::internal::ExponentialBackoffPolicy
 A truncated exponential backoff policy with randomized periods. More...
 
using RetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< pubsub_internal::RetryTraits >
 The base class for retry policies. More...
 
using LimitedTimeRetryPolicy = ::google::cloud::internal::LimitedTimeRetryPolicy< pubsub_internal::RetryTraits >
 A retry policy that limits based on time. More...
 
using LimitedErrorCountRetryPolicy = google::cloud::internal::LimitedErrorCountRetryPolicy< pubsub_internal::RetryTraits >
 A retry policy that limits the number of times a request can fail. More...
 
using ApplicationCallback = std::function< void(Message, AckHandler)>
 Defines the interface for application-level callbacks. More...
 
using ListSchemasRange = google::cloud::internal::PaginationRange< google::pubsub::v1::Schema >
 An input range to stream Cloud Pub/Sub schemas. More...
 
using seconds = std::chrono::seconds
 

Functions

std::shared_ptr< PublisherConnectionMakePublisherConnection (Topic topic, PublisherOptions options, ConnectionOptions connection_options={}, std::unique_ptr< RetryPolicy const > retry_policy={}, std::unique_ptr< BackoffPolicy const > backoff_policy={})
 Creates a new PublisherConnection object to work with Publisher. More...
 
std::shared_ptr< SubscriberConnectionMakeSubscriberConnection (Subscription subscription, SubscriberOptions options={}, ConnectionOptions connection_options={}, std::unique_ptr< pubsub::RetryPolicy const > retry_policy={}, std::unique_ptr< pubsub::BackoffPolicy const > backoff_policy={})
 Creates a new SubscriberConnection object to work with Subscriber. More...
 
std::shared_ptr< SubscriptionAdminConnectionMakeSubscriptionAdminConnection (ConnectionOptions const &options=ConnectionOptions(), std::unique_ptr< pubsub::RetryPolicy const > retry_policy={}, std::unique_ptr< pubsub::BackoffPolicy const > backoff_policy={})
 Returns an SubscriberConnection object to work with Cloud Pub/Sub subscriber APIs. More...
 
std::shared_ptr< TopicAdminConnectionMakeTopicAdminConnection (ConnectionOptions const &options=ConnectionOptions(), std::unique_ptr< pubsub::RetryPolicy const > retry_policy={}, std::unique_ptr< pubsub::BackoffPolicy const > backoff_policy={})
 Creates a new TopicAdminConnection object to work with TopicAdminClient. More...
 
bool operator== (Message const &a, Message const &b)
 
std::ostream & operator<< (std::ostream &os, Message const &rhs)
 
bool operator== (Schema const &a, Schema const &b)
 
std::ostream & operator<< (std::ostream &os, Schema const &rhs)
 
std::shared_ptr< SchemaAdminConnectionMakeSchemaAdminConnection (pubsub::ConnectionOptions const &options=pubsub::ConnectionOptions(), std::unique_ptr< pubsub::RetryPolicy const > retry_policy={}, std::unique_ptr< pubsub::BackoffPolicy const > backoff_policy={})
 Creates a new SchemaAdminConnection object to work with SchemaAdminClient. More...
 
bool operator== (Snapshot const &a, Snapshot const &b)
 
std::ostream & operator<< (std::ostream &os, Snapshot const &rhs)
 
bool operator== (Subscription const &a, Subscription const &b)
 
std::ostream & operator<< (std::ostream &os, Subscription const &rhs)
 
bool operator== (Topic const &a, Topic const &b)
 
std::ostream & operator<< (std::ostream &os, Topic const &rhs)
 

Detailed Description

The inlined, versioned namespace for the Cloud Pubsub C++ client APIs.

Applications may need to link multiple versions of the Cloud pubsub C++ client, for example, if they link a library that uses an older version of the client than they do. This namespace is inlined, so applications can use pubsub::Foo in their source, but the symbols are versioned, i.e., the symbol becomes pubsub::v1::Foo.

Typedef Documentation

◆ ApplicationCallback

using google::cloud::pubsub::v1::ApplicationCallback = typedef std::function<void(Message, AckHandler)>

Defines the interface for application-level callbacks.

Applications provide a callable compatible with this type to receive messages. They acknowledge (or reject) messages using AckHandler. This is a move-only type to support asynchronously acknowledgments.

Definition at line 35 of file application_callback.h.

◆ BackoffPolicy

using google::cloud::pubsub::v1::BackoffPolicy = typedef ::google::cloud::internal::BackoffPolicy

The base class for backoff policies.

Definition at line 27 of file backoff_policy.h.

◆ ConnectionOptions

using google::cloud::pubsub::v1::ConnectionOptions = typedef ::google::cloud::ConnectionOptions<ConnectionOptionsTraits>

Configure a connection for Cloud Pub/Sub services.

Definition at line 36 of file connection_options.h.

◆ ExponentialBackoffPolicy

using google::cloud::pubsub::v1::ExponentialBackoffPolicy = typedef google::cloud::internal::ExponentialBackoffPolicy

A truncated exponential backoff policy with randomized periods.

Definition at line 30 of file backoff_policy.h.

◆ LimitedErrorCountRetryPolicy

using google::cloud::pubsub::v1::LimitedErrorCountRetryPolicy = typedef google::cloud::internal::LimitedErrorCountRetryPolicy< pubsub_internal::RetryTraits>

A retry policy that limits the number of times a request can fail.

Definition at line 54 of file retry_policy.h.

◆ LimitedTimeRetryPolicy

using google::cloud::pubsub::v1::LimitedTimeRetryPolicy = typedef ::google::cloud::internal::LimitedTimeRetryPolicy< pubsub_internal::RetryTraits>

A retry policy that limits based on time.

Definition at line 49 of file retry_policy.h.

◆ ListSchemasRange

using google::cloud::pubsub::v1::ListSchemasRange = typedef google::cloud::internal::PaginationRange<google::pubsub::v1::Schema>

An input range to stream Cloud Pub/Sub schemas.

This type models an input range of google::pubsub::v1::Schema objects. Applications can make a single pass through the results.

Definition at line 42 of file schema_admin_connection.h.

◆ ListSnapshotsRange

using google::cloud::pubsub::v1::ListSnapshotsRange = typedef google::cloud::internal::PaginationRange<google::pubsub::v1::Snapshot>

An input range to stream Cloud Pub/Sub snapshots.

This type models an input range of google::pubsub::v1::Snapshot objects. Applications can make a single pass through the results.

Definition at line 57 of file subscription_admin_connection.h.

◆ ListSubscriptionsRange

using google::cloud::pubsub::v1::ListSubscriptionsRange = typedef google::cloud::internal::PaginationRange<google::pubsub::v1::Subscription>

An input range to stream Cloud Pub/Sub subscriptions.

This type models an input range of google::pubsub::v1::Subscription objects. Applications can make a single pass through the results.

Definition at line 45 of file subscription_admin_connection.h.

◆ ListTopicSnapshotsRange

using google::cloud::pubsub::v1::ListTopicSnapshotsRange = typedef google::cloud::internal::PaginationRange<std::string>

An input range to stream the Cloud Pub/Sub snapshots of a topic.

This type models an input range of std::string objects. Applications can make a single pass through the results.

Definition at line 69 of file topic_admin_connection.h.

◆ ListTopicsRange

using google::cloud::pubsub::v1::ListTopicsRange = typedef google::cloud::internal::PaginationRange<google::pubsub::v1::Topic>

An input range to stream Cloud Pub/Sub topics.

This type models an input range of google::pubsub::v1::Topic objects. Applications can make a single pass through the results.

Definition at line 45 of file topic_admin_connection.h.

◆ ListTopicSubscriptionsRange

using google::cloud::pubsub::v1::ListTopicSubscriptionsRange = typedef google::cloud::internal::PaginationRange<std::string>

An input range to stream the Cloud Pub/Sub subscriptions of a topic.

This type models an input range of std::string objects. Applications can make a single pass through the results.

Definition at line 57 of file topic_admin_connection.h.

◆ PubsubMessageDataType

using google::cloud::pubsub::v1::PubsubMessageDataType = typedef std::decay< decltype(std::declval<google::pubsub::v1::PubsubMessage>().data())>::type

Defines the type for message data.

Inside Google some protobuf fields of type bytes are mapped to a different type than std::string. This is the case for message data. We use this type to automatically detect what is the representation for this field and use the correct mapping.

External users of the Cloud Pubsub C++ client library should treat this as a complicated typedef for std::string. We have no plans to change the type in the external version of the C++ client library for the foreseeable future. In the eventuality that we do decide to change the type, this would be a reason update the library major version number, and we would give users time to migrate.

In other words, external users of the Cloud Pubsub C++ client should simply write std::string where this type appears. For Google projects that must compile both inside and outside Google, this alias may be convenient.

Definition at line 68 of file message.h.

◆ RetryPolicy

using google::cloud::pubsub::v1::RetryPolicy = typedef ::google::cloud::internal::TraitBasedRetryPolicy< pubsub_internal::RetryTraits>

The base class for retry policies.

Definition at line 45 of file retry_policy.h.

◆ seconds

using google::cloud::pubsub::v1::seconds = typedef std::chrono::seconds

Definition at line 23 of file subscriber_options.cc.

Function Documentation

◆ MakePublisherConnection()

std::shared_ptr< PublisherConnection > google::cloud::pubsub::v1::MakePublisherConnection ( Topic  topic,
PublisherOptions  options,
ConnectionOptions  connection_options = {},
std::unique_ptr< RetryPolicy const >  retry_policy = {},
std::unique_ptr< BackoffPolicy const >  backoff_policy = {} 
)

Creates a new PublisherConnection object to work with Publisher.

The PublisherConnection class is not intended for direct use in applications, it is provided for applications wanting to mock the PublisherClient behavior in their tests.

Performance
Creating a new PublisherConnection is relatively expensive. This typically initiate connections to the service, and therefore these objects should be shared and reused when possible. Note that gRPC reuses existing OS resources (sockets) whenever possible, so applications may experience better performance on the second (and subsequent) calls to this function with the same ConnectionOptions parameters. However, this behavior is not guaranteed and applications should not rely on it.
See also
PublisherConnection
Parameters
topicthe Cloud Pub/Sub topic used by the returned PublisherConnection.
optionsconfigure the batching policy and other parameters in the returned connection.
connection_options(optional) general configuration for this connection, this type is also used to configure pubsub::Subscriber.
retry_policy(optional) configure the retry loop. This is only used if retry_publish_failures() is enabled in options.
backoff_policy(optional) configure the backoff period between retries. This is only used if retry_publish_failures() is enabled in options.

Definition at line 71 of file publisher_connection.cc.

◆ MakeSchemaAdminConnection()

std::shared_ptr< SchemaAdminConnection > google::cloud::pubsub::v1::MakeSchemaAdminConnection ( pubsub::ConnectionOptions const &  options = pubsub::ConnectionOptions(),
std::unique_ptr< pubsub::RetryPolicy const >  retry_policy = {},
std::unique_ptr< pubsub::BackoffPolicy const >  backoff_policy = {} 
)

Creates a new SchemaAdminConnection object to work with SchemaAdminClient.

The SchemaAdminConnection class is provided for applications wanting to mock the SchemaAdminClient behavior in their tests. It is not intended for direct use.

Performance
Creating a new SchemaAdminConnection is relatively expensive. This typically initiate connections to the service, and therefore these objects should be shared and reused when possible. Note that gRPC reuses existing OS resources (sockets) whenever possible, so applications may experience better performance on the second (and subsequent) calls to this function with the same ConnectionOptions parameters. However, this behavior is not guaranteed and applications should not rely on it.
See also
SchemaAdminClient
Parameters
options(optional) configure the PublisherConnection created by this function.
retry_policycontrol for how long (or how many times) are retryable RPCs attempted.
backoff_policycontrols the backoff behavior between retry attempts, typically some form of exponential backoff with jitter.

Definition at line 164 of file schema_admin_connection.cc.

◆ MakeSubscriberConnection()

std::shared_ptr< SubscriberConnection > google::cloud::pubsub::v1::MakeSubscriberConnection ( Subscription  subscription,
SubscriberOptions  options = {},
ConnectionOptions  connection_options = {},
std::unique_ptr< pubsub::RetryPolicy const >  retry_policy = {},
std::unique_ptr< pubsub::BackoffPolicy const >  backoff_policy = {} 
)

Creates a new SubscriberConnection object to work with Subscriber.

The SubscriberConnection class is not intended for direct use in applications, it is provided for applications wanting to mock the SubscriberClient behavior in their tests.

Performance
Creating a new SubscriberConnection is relatively expensive. This typically initiate connections to the service, and therefore these objects should be shared and reused when possible. Note that gRPC reuses existing OS resources (sockets) whenever possible, so applications may experience better performance on the second (and subsequent) calls to this function with the same ConnectionOptions parameters. However, this behavior is not guaranteed and applications should not rely on it.
See also
SubscriberConnection
Changing Retry Parameters Example
namespace pubsub = ::google::cloud::pubsub;
using ::google::cloud::future;
using ::google::cloud::StatusOr;
auto sample = [](std::string project_id, std::string subscription_id) {
// By default a subscriber will retry for 60 seconds, with an initial
// backoff of 100ms, a maximum backoff of 60 seconds, and the backoff will
// grow by 30% after each attempt. This changes those defaults.
pubsub::Subscription(std::move(project_id), std::move(subscription_id)),
/*maximum_duration=*/std::chrono::minutes(1))
.clone(),
/*initial_delay=*/std::chrono::milliseconds(200),
/*maximum_delay=*/std::chrono::seconds(10),
/*scaling=*/2.0)
.clone()));
auto session = subscriber.Subscribe(
std::move(h).ack();
std::cout << "Received message " << m << "\n";
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
Configure how a Subscriber handles incoming messages.
Receive messages from the Cloud Pub/Sub service.
Definition: subscriber.h:89
Objects of this class identify a Cloud Pub/Sub subscription.
Definition: subscription.h:37
::google::cloud::internal::LimitedTimeRetryPolicy< pubsub_internal::RetryTraits > LimitedTimeRetryPolicy
A retry policy that limits based on time.
Definition: retry_policy.h:51
std::shared_ptr< SubscriberConnection > MakeSubscriberConnection(Subscription subscription, SubscriberOptions options={}, ConnectionOptions connection_options={}, std::unique_ptr< pubsub::RetryPolicy const > retry_policy={}, std::unique_ptr< pubsub::BackoffPolicy const > backoff_policy={})
Creates a new SubscriberConnection object to work with Subscriber.
::google::cloud::ConnectionOptions< ConnectionOptionsTraits > ConnectionOptions
Configure a connection for Cloud Pub/Sub services.
google::cloud::internal::ExponentialBackoffPolicy ExponentialBackoffPolicy
A truncated exponential backoff policy with randomized periods.
std::chrono::seconds seconds
Contains all the Cloud Pubsub C++ client types and functions.
Definition: ack_handler.cc:20
Parameters
subscriptionthe Cloud Pub/Sub subscription used by the returned connection.
optionsconfigure the flow control and other parameters in the returned connection.
connection_options(optional) general configuration for this connection, this type is also used to configure pubsub::Publisher.
retry_policycontrol for how long (or how many times) are retryable RPCs attempted.
backoff_policycontrols the backoff behavior between retry attempts, typically some form of exponential backoff with jitter.

Definition at line 41 of file subscriber_connection.cc.

◆ MakeSubscriptionAdminConnection()

std::shared_ptr< SubscriptionAdminConnection > google::cloud::pubsub::v1::MakeSubscriptionAdminConnection ( ConnectionOptions const &  options = ConnectionOptions(),
std::unique_ptr< pubsub::RetryPolicy const >  retry_policy = {},
std::unique_ptr< pubsub::BackoffPolicy const >  backoff_policy = {} 
)

Returns an SubscriberConnection object to work with Cloud Pub/Sub subscriber APIs.

The SubscriberConnection class is not intended for direct use in applications, it is provided for applications wanting to mock the SubscriberClient behavior in their tests.

Performance
Creating a new SubscriptionAdminConnection is relatively expensive. This typically initiate connections to the service, and therefore these objects should be shared and reused when possible. Note that gRPC reuses existing OS resources (sockets) whenever possible, so applications may experience better performance on the second (and subsequent) calls to this function with the same ConnectionOptions parameters. However, this behavior is not guaranteed and applications should not rely on it.
See also
SubscriberConnection
Parameters
options(optional) configure the SubscriberConnection created by this function.
retry_policycontrol for how long (or how many times) are retryable RPCs attempted.
backoff_policycontrols the backoff behavior between retry attempts, typically some form of exponential backoff with jitter.

Definition at line 272 of file subscription_admin_connection.cc.

◆ MakeTopicAdminConnection()

std::shared_ptr< TopicAdminConnection > google::cloud::pubsub::v1::MakeTopicAdminConnection ( ConnectionOptions const &  options = ConnectionOptions(),
std::unique_ptr< pubsub::RetryPolicy const >  retry_policy = {},
std::unique_ptr< pubsub::BackoffPolicy const >  backoff_policy = {} 
)

Creates a new TopicAdminConnection object to work with TopicAdminClient.

The TopicAdminConnection class is provided for applications wanting to mock the TopicAdminClient behavior in their tests. It is not intended for direct use.

Performance
Creating a new TopicAdminConnection is relatively expensive. This typically initiate connections to the service, and therefore these objects should be shared and reused when possible. Note that gRPC reuses existing OS resources (sockets) whenever possible, so applications may experience better performance on the second (and subsequent) calls to this function with the same ConnectionOptions parameters. However, this behavior is not guaranteed and applications should not rely on it.
See also
TopicAdminClient
Parameters
options(optional) configure the PublisherConnection created by this function.
retry_policycontrol for how long (or how many times) are retryable RPCs attempted.
backoff_policycontrols the backoff behavior between retry attempts, typically some form of exponential backoff with jitter.

Definition at line 288 of file topic_admin_connection.cc.

◆ operator<<() [1/5]

std::ostream& google::cloud::pubsub::v1::operator<< ( std::ostream &  os,
Message const &  rhs 
)

Definition at line 55 of file message.cc.

◆ operator<<() [2/5]

std::ostream& google::cloud::pubsub::v1::operator<< ( std::ostream &  os,
Schema const &  rhs 
)

Definition at line 30 of file schema.cc.

◆ operator<<() [3/5]

std::ostream& google::cloud::pubsub::v1::operator<< ( std::ostream &  os,
Snapshot const &  rhs 
)

Definition at line 30 of file snapshot.cc.

◆ operator<<() [4/5]

std::ostream& google::cloud::pubsub::v1::operator<< ( std::ostream &  os,
Subscription const &  rhs 
)

Definition at line 31 of file subscription.cc.

◆ operator<<() [5/5]

std::ostream& google::cloud::pubsub::v1::operator<< ( std::ostream &  os,
Topic const &  rhs 
)

Definition at line 30 of file topic.cc.

◆ operator==() [1/5]

bool google::cloud::pubsub::v1::operator== ( Message const &  a,
Message const &  b 
)

Definition at line 50 of file message.cc.

◆ operator==() [2/5]

bool google::cloud::pubsub::v1::operator== ( Schema const &  a,
Schema const &  b 
)

Definition at line 26 of file schema.cc.

◆ operator==() [3/5]

bool google::cloud::pubsub::v1::operator== ( Snapshot const &  a,
Snapshot const &  b 
)

Definition at line 26 of file snapshot.cc.

◆ operator==() [4/5]

bool google::cloud::pubsub::v1::operator== ( Subscription const &  a,
Subscription const &  b 
)

Definition at line 26 of file subscription.cc.

◆ operator==() [5/5]

bool google::cloud::pubsub::v1::operator== ( Topic const &  a,
Topic const &  b 
)

Definition at line 26 of file topic.cc.