Google Cloud Pub/Sub C++ Client 2.13.0
A C++ Client Library for Google Cloud Pub/Sub
Loading...
Searching...
No Matches
Public Member Functions | List of all members
google::cloud::pubsub::SubscriptionAdminClient Class Reference

Performs subscription administrative operations in Cloud Pub/Sub. More...

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

Public Member Functions

 SubscriptionAdminClient (std::shared_ptr< SubscriptionAdminConnection > connection, Options opts={})
 
 SubscriptionAdminClient ()=delete
 The default constructor is deleted. More...
 
StatusOr< google::pubsub::v1::Subscription > CreateSubscription (Topic const &topic, Subscription const &subscription, SubscriptionBuilder builder={}, Options opts={})
 Creates a new subscription in Cloud Pub/Sub. More...
 
StatusOr< google::pubsub::v1::Subscription > GetSubscription (Subscription subscription, Options opts={})
 Gets the metadata for an existing Cloud Pub/Sub subscription. More...
 
StatusOr< google::pubsub::v1::Subscription > UpdateSubscription (Subscription const &subscription, SubscriptionBuilder builder, Options opts={})
 Updates an existing subscription in Cloud Pub/Sub. More...
 
ListSubscriptionsRange ListSubscriptions (std::string const &project_id, Options opts={})
 Lists all the subscriptions for a given project id. More...
 
Status DeleteSubscription (Subscription subscription, Options opts={})
 Deletes an existing subscription in Cloud Pub/Sub. More...
 
Status ModifyPushSubscription (Subscription const &subscription, PushConfigBuilder builder, Options opts={})
 Modifies an existing subscription's push configuration. More...
 
StatusOr< google::pubsub::v1::Snapshot > CreateSnapshot (Subscription const &subscription, SnapshotBuilder builder={}, Options opts={})
 Creates a new snapshot for a subscription with a server-assigned name. More...
 
StatusOr< google::pubsub::v1::Snapshot > CreateSnapshot (Subscription const &subscription, Snapshot const &snapshot, SnapshotBuilder builder={}, Options opts={})
 Creates a new snapshot for a subscription with a given name. More...
 
StatusOr< google::pubsub::v1::Snapshot > GetSnapshot (Snapshot const &snapshot, Options opts={})
 Gets information about an existing snapshot. More...
 
StatusOr< google::pubsub::v1::Snapshot > UpdateSnapshot (Snapshot const &snapshot, SnapshotBuilder builder, Options opts={})
 Updates an existing snapshot. More...
 
ListSnapshotsRange ListSnapshots (std::string const &project_id, Options opts={})
 Lists all the snapshots for a given project id. More...
 
Status DeleteSnapshot (Snapshot const &snapshot, Options opts={})
 Deletes a snapshot. More...
 
StatusOr< google::pubsub::v1::SeekResponse > Seek (Subscription const &subscription, std::chrono::system_clock::time_point timestamp, Options opts={})
 Seeks a subscription to its state at timestamp. More...
 
StatusOr< google::pubsub::v1::SeekResponse > Seek (Subscription const &subscription, Snapshot const &snapshot, Options opts={})
 Seeks a subscription to its state at snapshot. More...
 

Detailed Description

Performs subscription administrative operations in Cloud Pub/Sub.

Applications use this class to perform subscription administrative operations on Cloud Pub/Sub.

Performance
SubscriptionAdminClient objects are relatively cheap to create, copy, and move. However, each SubscriptionAdminClient object must be created with a std::shared_ptr<SubscriptionAdminConnection>, which itself is relatively expensive to create. Therefore, connection instances should be shared when possible. See the MakeSubscriptionAdminConnection() function and the SubscriptionAdminConnection interface for more details.
Thread Safety
Instances of this class created via copy-construction or copy-assignment share the underlying pool of connections. Access to these copies via multiple threads is guaranteed to work. Two threads operating on the same instance of this class is not guaranteed to work.
Error Handling
This class uses 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 `StatusOr<T>` documentation for more details.

Constructor & Destructor Documentation

◆ SubscriptionAdminClient() [1/2]

google::cloud::pubsub::SubscriptionAdminClient::SubscriptionAdminClient ( std::shared_ptr< SubscriptionAdminConnection connection,
Options  opts = {} 
)
explicit

◆ SubscriptionAdminClient() [2/2]

google::cloud::pubsub::SubscriptionAdminClient::SubscriptionAdminClient ( )
delete

The default constructor is deleted.

Use SubscriberClient(std::shared_ptr<SubscriberConnection>)

Member Function Documentation

◆ CreateSnapshot() [1/2]

StatusOr< google::pubsub::v1::Snapshot > google::cloud::pubsub::SubscriptionAdminClient::CreateSnapshot ( Subscription const &  subscription,
Snapshot const &  snapshot,
SnapshotBuilder  builder = {},
Options  opts = {} 
)
inline

Creates a new snapshot for a subscription with a given name.

Idempotency
This operation is idempotent, the state of the system is the same after one or several calls, and therefore it is always retried.
Example
namespace pubsub = ::google::cloud::pubsub;
[](pubsub::SubscriptionAdminClient client, std::string const& project_id,
std::string const& subscription_id, std::string const& snapshot_id) {
auto snapshot = client.CreateSnapshot(
pubsub::Subscription(project_id, subscription_id),
pubsub::Snapshot(project_id, std::move(snapshot_id)));
if (snapshot.status().code() == google::cloud::StatusCode::kAlreadyExists) {
std::cout << "The snapshot already exists\n";
return;
}
if (!snapshot.ok()) throw std::move(snapshot).status();
std::cout << "The snapshot was successfully created: "
<< snapshot->DebugString() << "\n";
}
Objects of this class identify a Cloud Pub/Sub snapshot.
Definition: snapshot.h:37
Performs subscription administrative operations in Cloud Pub/Sub.
Definition: subscription_admin_client.h:60
StatusOr< google::pubsub::v1::Snapshot > CreateSnapshot(Subscription const &subscription, SnapshotBuilder builder={}, Options opts={})
Creates a new snapshot for a subscription with a server-assigned name.
Definition: subscription_admin_client.h:224
Objects of this class identify a Cloud Pub/Sub subscription.
Definition: subscription.h:37
Parameters
subscriptionthe name of the subscription
snapshotthe name of the snapshot
builderadditional configuration for the snapshot, e.g., labels
optsOverride the class-level options, such as retry and backoff policies.
See also
https://cloud.google.com/pubsub/docs/replay-overview for a detailed description of Cloud Pub/Sub's snapshots.

◆ CreateSnapshot() [2/2]

StatusOr< google::pubsub::v1::Snapshot > google::cloud::pubsub::SubscriptionAdminClient::CreateSnapshot ( Subscription const &  subscription,
SnapshotBuilder  builder = {},
Options  opts = {} 
)
inline

Creates a new snapshot for a subscription with a server-assigned name.

Idempotency
This is not an idempotent operation, repeated calls would create multiple snapshots with different names assigned by the service, and therefore it is never retried.
Parameters
subscriptionthe name of the subscription
builderadditional configuration for the snapshot, e.g., labels
optsOverride the class-level options, such as retry and backoff policies.

◆ CreateSubscription()

StatusOr< google::pubsub::v1::Subscription > google::cloud::pubsub::SubscriptionAdminClient::CreateSubscription ( Topic const &  topic,
Subscription const &  subscription,
SubscriptionBuilder  builder = {},
Options  opts = {} 
)
inline

Creates a new subscription in Cloud Pub/Sub.

Idempotency
This operation is idempotent, the state of the system is the same after one or several calls, and therefore it is always retried. It might return a status code of kAlreadyExists as a consequence of retrying a successful (but reported as failed) request.
Example: Create a Pull Subscription
namespace pubsub = ::google::cloud::pubsub;
[](pubsub::SubscriptionAdminClient client, std::string const& project_id,
std::string const& topic_id, std::string const& subscription_id) {
auto sub = client.CreateSubscription(
pubsub::Topic(project_id, std::move(topic_id)),
pubsub::Subscription(project_id, std::move(subscription_id)));
if (sub.status().code() == google::cloud::StatusCode::kAlreadyExists) {
std::cout << "The subscription already exists\n";
return;
}
if (!sub) throw std::move(sub).status();
std::cout << "The subscription was successfully created: "
<< sub->DebugString() << "\n";
}
StatusOr< google::pubsub::v1::Subscription > CreateSubscription(Topic const &topic, Subscription const &subscription, SubscriptionBuilder builder={}, Options opts={})
Creates a new subscription in Cloud Pub/Sub.
Definition: subscription_admin_client.h:97
Objects of this class identify a Cloud Pub/Sub topic.
Definition: topic.h:37
Example: Create a Push Subscription
namespace pubsub = ::google::cloud::pubsub;
[](pubsub::SubscriptionAdminClient client, std::string const& project_id,
std::string const& topic_id, std::string const& subscription_id,
std::string const& endpoint) {
auto sub = client.CreateSubscription(
pubsub::Topic(project_id, std::move(topic_id)),
pubsub::Subscription(project_id, std::move(subscription_id)),
if (sub.status().code() == google::cloud::StatusCode::kAlreadyExists) {
std::cout << "The subscription already exists\n";
return;
}
if (!sub) throw std::move(sub).status();
std::cout << "The subscription was successfully created: "
<< sub->DebugString() << "\n";
}
Helper class to create google::pubsub::v1::PushConfig protos.
Definition: subscription_builder.h:44
PushConfigBuilder & set_push_endpoint(std::string v) &
Definition: subscription_builder.h:57
Create a Cloud Pub/Sub subscription configuration.
Definition: subscription_builder.h:317
SubscriptionBuilder & set_push_config(PushConfigBuilder v) &
Example: Create a BigQuery Subscription
namespace pubsub = ::google::cloud::pubsub;
[](pubsub::SubscriptionAdminClient client, std::string const& project_id,
std::string const& topic_id, std::string const& subscription_id,
std::string const& table_id) {
auto sub = client.CreateSubscription(
pubsub::Topic(project_id, std::move(topic_id)),
pubsub::Subscription(project_id, std::move(subscription_id)),
if (sub.status().code() == google::cloud::StatusCode::kAlreadyExists) {
std::cout << "The subscription already exists\n";
return;
}
if (!sub) throw std::move(sub).status();
std::cout << "The subscription was successfully created: "
<< sub->DebugString() << "\n";
}
A helper class to build google::pubsub::v1::BigQueryConfig protos.
Definition: subscription_builder.h:145
BigQueryConfigBuilder & set_table(std::string full_path) &
Definition: subscription_builder.h:151
SubscriptionBuilder & set_bigquery_config(BigQueryConfigBuilder v) &
Parameters
topicthe topic that the subscription will attach to
subscriptionthe name for the subscription
builderany additional configuration for the subscription
optsOverride the class-level options, such as retry and backoff policies.

◆ DeleteSnapshot()

Status google::cloud::pubsub::SubscriptionAdminClient::DeleteSnapshot ( Snapshot const &  snapshot,
Options  opts = {} 
)
inline

Deletes a snapshot.

Idempotency
This operation is idempotent, the state of the system is the same after one or several calls, and therefore it is always retried.
Example
namespace pubsub = ::google::cloud::pubsub;
[](pubsub::SubscriptionAdminClient client, std::string const& project_id,
std::string const& subscription_id, std::string const& snapshot_id) {
auto snapshot = client.CreateSnapshot(
pubsub::Subscription(project_id, subscription_id),
pubsub::Snapshot(project_id, std::move(snapshot_id)));
if (snapshot.status().code() == google::cloud::StatusCode::kAlreadyExists) {
std::cout << "The snapshot already exists\n";
return;
}
if (!snapshot.ok()) throw std::move(snapshot).status();
std::cout << "The snapshot was successfully created: "
<< snapshot->DebugString() << "\n";
}
Parameters
snapshotthe name of the snapshot
optsOverride the class-level options, such as retry and backoff policies.
See also
https://cloud.google.com/pubsub/docs/replay-overview for a detailed description of Cloud Pub/Sub's snapshots.

◆ DeleteSubscription()

Status google::cloud::pubsub::SubscriptionAdminClient::DeleteSubscription ( Subscription  subscription,
Options  opts = {} 
)
inline

Deletes an existing subscription in Cloud Pub/Sub.

Idempotency
This operation is idempotent, the state of the system is the same after one or several calls, and therefore it is always retried. It might return a status code of kNotFound as a consequence of retrying a successful (but reported as failed) request.
Example
namespace pubsub = ::google::cloud::pubsub;
[](pubsub::SubscriptionAdminClient client, std::string const& project_id,
std::string const& subscription_id) {
std::move(project_id), std::move(subscription_id)));
// Note that kNotFound is a possible result when the library retries.
if (status.code() == google::cloud::StatusCode::kNotFound) {
std::cout << "The subscription was not found\n";
return;
}
if (!status.ok()) throw std::runtime_error(status.message());
std::cout << "The subscription was successfully deleted\n";
}
Status DeleteSubscription(Subscription subscription, Options opts={})
Deletes an existing subscription in Cloud Pub/Sub.
Definition: subscription_admin_client.h:178
Parameters
subscriptionthe name of the subscription to be deleted.
optsOverride the class-level options, such as retry and backoff policies.

◆ GetSnapshot()

StatusOr< google::pubsub::v1::Snapshot > google::cloud::pubsub::SubscriptionAdminClient::GetSnapshot ( Snapshot const &  snapshot,
Options  opts = {} 
)
inline

Gets information about an existing snapshot.

Idempotency
This is a read-only operation and therefore always idempotent and retried.
Example
namespace pubsub = ::google::cloud::pubsub;
[](pubsub::SubscriptionAdminClient client, std::string const& project_id,
std::string const& snapshot_id) {
auto response = client.GetSnapshot(
pubsub::Snapshot(std::move(project_id), std::move(snapshot_id)));
if (!response.ok()) throw std::move(response).status();
std::cout << "The snapshot details are: " << response->DebugString()
<< "\n";
}
StatusOr< google::pubsub::v1::Snapshot > GetSnapshot(Snapshot const &snapshot, Options opts={})
Gets information about an existing snapshot.
Definition: subscription_admin_client.h:277
Parameters
snapshotthe name of the snapshot
optsOverride the class-level options, such as retry and backoff policies.
See also
https://cloud.google.com/pubsub/docs/replay-overview for a detailed description of Cloud Pub/Sub's snapshots.

◆ GetSubscription()

StatusOr< google::pubsub::v1::Subscription > google::cloud::pubsub::SubscriptionAdminClient::GetSubscription ( Subscription  subscription,
Options  opts = {} 
)
inline

Gets the metadata for an existing Cloud Pub/Sub subscription.

Idempotency
This is a read-only operation and therefore always idempotent and retried.
Example
namespace pubsub = ::google::cloud::pubsub;
[](pubsub::SubscriptionAdminClient client, std::string const& project_id,
std::string const& subscription_id) {
auto sub = client.GetSubscription(
pubsub::Subscription(project_id, std::move(subscription_id)));
if (!sub) throw std::move(sub).status();
std::cout << "The subscription exists and its metadata is: "
<< sub->DebugString() << "\n";
}
StatusOr< google::pubsub::v1::Subscription > GetSubscription(Subscription subscription, Options opts={})
Gets the metadata for an existing Cloud Pub/Sub subscription.
Definition: subscription_admin_client.h:115

◆ ListSnapshots()

ListSnapshotsRange google::cloud::pubsub::SubscriptionAdminClient::ListSnapshots ( std::string const &  project_id,
Options  opts = {} 
)
inline

Lists all the snapshots for a given project id.

Idempotency
This is a read-only operation and therefore always idempotent and retried.
Example
namespace pubsub = ::google::cloud::pubsub;
[](pubsub::SubscriptionAdminClient client, std::string const& project_id) {
std::cout << "Snapshot list for project " << project_id << ":\n";
for (auto& snapshot : client.ListSnapshots(project_id)) {
if (!snapshot) throw std::move(snapshot).status();
std::cout << "Snapshot Name: " << snapshot->name() << "\n";
}
}
ListSnapshotsRange ListSnapshots(std::string const &project_id, Options opts={})
Lists all the snapshots for a given project id.
Definition: subscription_admin_client.h:322
See also
https://cloud.google.com/pubsub/docs/replay-overview for a detailed description of Cloud Pub/Sub's snapshots.

◆ ListSubscriptions()

ListSubscriptionsRange google::cloud::pubsub::SubscriptionAdminClient::ListSubscriptions ( std::string const &  project_id,
Options  opts = {} 
)
inline

Lists all the subscriptions for a given project id.

Idempotency
This is a read-only operation and therefore always idempotent and retried.
Example
namespace pubsub = ::google::cloud::pubsub;
[](pubsub::SubscriptionAdminClient client, std::string const& project_id) {
int count = 0;
for (auto& subscription : client.ListSubscriptions(project_id)) {
if (!subscription) throw std::move(subscription).status();
std::cout << "Subscription Name: " << subscription->name() << "\n";
++count;
}
if (count == 0) {
std::cout << "No subscriptions found in project " << project_id << "\n";
}
}
ListSubscriptionsRange ListSubscriptions(std::string const &project_id, Options opts={})
Lists all the subscriptions for a given project id.
Definition: subscription_admin_client.h:155

◆ ModifyPushSubscription()

Status google::cloud::pubsub::SubscriptionAdminClient::ModifyPushSubscription ( Subscription const &  subscription,
PushConfigBuilder  builder,
Options  opts = {} 
)
inline

Modifies an existing subscription's push configuration.

This can change a push subscription into a pull subscription (by setting an empty push config), change the push endpoint, or change a pull subscription into a push config.

Idempotency
This operation is idempotent, the state of the system is the same after one or several calls, and therefore it is always retried.
Example
namespace pubsub = ::google::cloud::pubsub;
[](pubsub::SubscriptionAdminClient client, std::string const& project_id,
std::string const& subscription_id, std::string const& endpoint) {
auto status = client.ModifyPushSubscription(
pubsub::Subscription(project_id, std::move(subscription_id)),
if (!status.ok()) throw std::runtime_error(status.message());
std::cout << "The subscription push configuration was successfully"
<< " modified\n";
}
Status ModifyPushSubscription(Subscription const &subscription, PushConfigBuilder builder, Options opts={})
Modifies an existing subscription's push configuration.
Definition: subscription_admin_client.h:203
Parameters
subscriptionthe name of the subscription to be modified.
buildera description of the changes to be made.
optsOverride the class-level options, such as retry and backoff policies.

◆ Seek() [1/2]

StatusOr< google::pubsub::v1::SeekResponse > google::cloud::pubsub::SubscriptionAdminClient::Seek ( Subscription const &  subscription,
Snapshot const &  snapshot,
Options  opts = {} 
)

Seeks a subscription to its state at snapshot.

Idempotency
This operation is idempotent, the state of the system is the same after one or several calls, and therefore it is always retried.
Example
namespace pubsub = ::google::cloud::pubsub;
[](pubsub::SubscriptionAdminClient client, std::string const& project_id,
std::string const& subscription_id, std::string const& seconds) {
auto response =
client.Seek(pubsub::Subscription(project_id, subscription_id),
std::chrono::system_clock::now() -
std::chrono::seconds(std::stoi(seconds)));
if (!response.ok()) throw std::move(response).status();
std::cout << "The subscription seek was successful: "
<< response->DebugString() << "\n";
}
StatusOr< google::pubsub::v1::SeekResponse > Seek(Subscription const &subscription, std::chrono::system_clock::time_point timestamp, Options opts={})
Seeks a subscription to its state at timestamp.
See also
https://cloud.google.com/pubsub/docs/replay-overview for a detailed description of Cloud Pub/Sub's Seek() functionality.

◆ Seek() [2/2]

StatusOr< google::pubsub::v1::SeekResponse > google::cloud::pubsub::SubscriptionAdminClient::Seek ( Subscription const &  subscription,
std::chrono::system_clock::time_point  timestamp,
Options  opts = {} 
)

Seeks a subscription to its state at timestamp.

Messages retained in the subscription that were published before timestamp are marked as acknowledged, while messages published after timestamp are marked as unacknowledged.

Idempotency
This operation is idempotent, the state of the system is the same after one or several calls, and therefore it is always retried.
Example
namespace pubsub = ::google::cloud::pubsub;
[](pubsub::SubscriptionAdminClient client, std::string const& project_id,
std::string const& subscription_id, std::string const& seconds) {
auto response =
client.Seek(pubsub::Subscription(project_id, subscription_id),
std::chrono::system_clock::now() -
std::chrono::seconds(std::stoi(seconds)));
if (!response.ok()) throw std::move(response).status();
std::cout << "The subscription seek was successful: "
<< response->DebugString() << "\n";
}
See also
https://cloud.google.com/pubsub/docs/replay-overview for a detailed description of Cloud Pub/Sub's Seek() functionality.

◆ UpdateSnapshot()

StatusOr< google::pubsub::v1::Snapshot > google::cloud::pubsub::SubscriptionAdminClient::UpdateSnapshot ( Snapshot const &  snapshot,
SnapshotBuilder  builder,
Options  opts = {} 
)
inline

Updates an existing snapshot.

Idempotency
This operation is idempotent, the state of the system is the same after one or several calls, and therefore it is always retried.
Example
namespace pubsub = ::google::cloud::pubsub;
[](pubsub::SubscriptionAdminClient client, std::string const& project_id,
std::string snapshot_id) {
auto snap = client.UpdateSnapshot(
pubsub::Snapshot(project_id, std::move(snapshot_id)),
pubsub::SnapshotBuilder{}.add_label("samples-cpp", "gcp"));
if (!snap.ok()) throw std::move(snap).status();
std::cout << "The snapshot was successfully updated: "
<< snap->DebugString() << "\n";
}
Build a request to create a Cloud Pub/Sub snapshot.
Definition: snapshot_builder.h:41
SnapshotBuilder & add_label(std::string const &key, std::string const &value) &
Definition: snapshot_builder.h:61
StatusOr< google::pubsub::v1::Snapshot > UpdateSnapshot(Snapshot const &snapshot, SnapshotBuilder builder, Options opts={})
Updates an existing snapshot.
Definition: subscription_admin_client.h:302
Parameters
snapshotthe name of the snapshot
builderthe changes applied to the snapshot
optsOverride the class-level options, such as retry and backoff policies.
See also
https://cloud.google.com/pubsub/docs/replay-overview for a detailed description of Cloud Pub/Sub's snapshots.

◆ UpdateSubscription()

StatusOr< google::pubsub::v1::Subscription > google::cloud::pubsub::SubscriptionAdminClient::UpdateSubscription ( Subscription const &  subscription,
SubscriptionBuilder  builder,
Options  opts = {} 
)
inline

Updates an existing subscription in Cloud Pub/Sub.

Idempotency
This operation is idempotent, the state of the system is the same after one or several calls, and therefore it is always retried.
Example
namespace pubsub = ::google::cloud::pubsub;
[](pubsub::SubscriptionAdminClient client, std::string const& project_id,
std::string const& subscription_id) {
auto s = client.UpdateSubscription(
pubsub::Subscription(project_id, std::move(subscription_id)),
std::chrono::seconds(60)));
if (!s) throw std::move(s).status();
std::cout << "The subscription has been updated to: " << s->DebugString()
<< "\n";
}
StatusOr< google::pubsub::v1::Subscription > UpdateSubscription(Subscription const &subscription, SubscriptionBuilder builder, Options opts={})
Updates an existing subscription in Cloud Pub/Sub.
Definition: subscription_admin_client.h:137
SubscriptionBuilder & set_ack_deadline(std::chrono::seconds v) &
Definition: subscription_builder.h:347
Parameters
subscriptionthe name for the subscription
builderany additional configuration for the subscription
optsOverride the class-level options, such as retry and backoff policies.