This shows how to override the retry policies for storagebatchoperations_v1::StorageBatchOperationsClient:
auto options =
google::cloud::Options{}
.set<google::cloud::storagebatchoperations_v1::
StorageBatchOperationsConnectionIdempotencyPolicyOption>(
CustomIdempotencyPolicy().clone())
.set<google::cloud::storagebatchoperations_v1::
StorageBatchOperationsRetryPolicyOption>(
google::cloud::storagebatchoperations_v1::
StorageBatchOperationsLimitedErrorCountRetryPolicy(3)
.clone())
.set<google::cloud::storagebatchoperations_v1::
StorageBatchOperationsBackoffPolicyOption>(
google::cloud::ExponentialBackoffPolicy(
/*initial_delay=*/std::chrono::milliseconds(200),
/*maximum_delay=*/std::chrono::seconds(45),
/*scaling=*/2.0)
.clone());
auto connection = google::cloud::storagebatchoperations_v1::
MakeStorageBatchOperationsConnection(options);
// c1 and c2 share the same retry policies
auto c1 =
google::cloud::storagebatchoperations_v1::StorageBatchOperationsClient(
connection);
auto c2 =
google::cloud::storagebatchoperations_v1::StorageBatchOperationsClient(
connection);
// You can override any of the policies in a new client. This new client
// will share the policies from c1 (or c2) *except* for the retry policy.
auto c3 =
google::cloud::storagebatchoperations_v1::StorageBatchOperationsClient(
connection, google::cloud::Options{}
.set<google::cloud::storagebatchoperations_v1::
StorageBatchOperationsRetryPolicyOption>(
google::cloud::storagebatchoperations_v1::
StorageBatchOperationsLimitedTimeRetryPolicy(
std::chrono::minutes(5))
.clone()));
// You can also override the policies in a single call:
// c3.SomeRpc(..., google::cloud::Options{}
// .set<google::cloud::storagebatchoperations_v1::StorageBatchOperationsRetryPolicyOption>(
// google::cloud::storagebatchoperations_v1::StorageBatchOperationsLimitedErrorCountRetryPolicy(10).clone()));
Assuming you have created a custom idempotency policy. Such as:
class CustomIdempotencyPolicy
: public google::cloud::storagebatchoperations_v1::
StorageBatchOperationsConnectionIdempotencyPolicy {
public:
~CustomIdempotencyPolicy() override = default;
std::unique_ptr<google::cloud::storagebatchoperations_v1::
StorageBatchOperationsConnectionIdempotencyPolicy>
clone() const override {
return std::make_unique<CustomIdempotencyPolicy>(*this);
}
// Override inherited functions to define as needed.
};
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[],[],null,["Version latestkeyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/storagebatchoperations/latest/storagebatchoperations_v1_1_1StorageBatchOperationsClient-retry-snippet)\n- [2.41.0](/cpp/docs/reference/storagebatchoperations/2.41.0/storagebatchoperations_v1_1_1StorageBatchOperationsClient-retry-snippet)\n- [2.40.0](/cpp/docs/reference/storagebatchoperations/2.40.0/storagebatchoperations_v1_1_1StorageBatchOperationsClient-retry-snippet)\n- [2.39.0](/cpp/docs/reference/storagebatchoperations/2.39.0/storagebatchoperations_v1_1_1StorageBatchOperationsClient-retry-snippet)\n- [2.38.0](/cpp/docs/reference/storagebatchoperations/2.38.0/storagebatchoperations_v1_1_1StorageBatchOperationsClient-retry-snippet)\n- [2.37.0](/cpp/docs/reference/storagebatchoperations/2.37.0/storagebatchoperations_v1_1_1StorageBatchOperationsClient-retry-snippet) \n\nOverride storagebatchoperations_v1::StorageBatchOperationsClient Retry Policies\n===============================================================================\n\nThis shows how to override the retry policies for storagebatchoperations_v1::StorageBatchOperationsClient: \n\n auto options =\n google::cloud::Options{}\n .set\u003cgoogle::cloud::storagebatchoperations_v1::\n StorageBatchOperationsConnectionIdempotencyPolicyOption\u003e(\n CustomIdempotencyPolicy().clone())\n .set\u003cgoogle::cloud::storagebatchoperations_v1::\n StorageBatchOperationsRetryPolicyOption\u003e(\n google::cloud::storagebatchoperations_v1::\n StorageBatchOperationsLimitedErrorCountRetryPolicy(3)\n .clone())\n .set\u003cgoogle::cloud::storagebatchoperations_v1::\n StorageBatchOperationsBackoffPolicyOption\u003e(\n google::cloud::ExponentialBackoffPolicy(\n /*initial_delay=*/std::chrono::milliseconds(200),\n /*maximum_delay=*/std::chrono::seconds(45),\n /*scaling=*/2.0)\n .clone());\n auto connection = google::cloud::storagebatchoperations_v1::\n MakeStorageBatchOperationsConnection(options);\n\n // c1 and c2 share the same retry policies\n auto c1 =\n google::cloud::storagebatchoperations_v1::StorageBatchOperationsClient(\n connection);\n auto c2 =\n google::cloud::storagebatchoperations_v1::StorageBatchOperationsClient(\n connection);\n\n // You can override any of the policies in a new client. This new client\n // will share the policies from c1 (or c2) *except* for the retry policy.\n auto c3 =\n google::cloud::storagebatchoperations_v1::StorageBatchOperationsClient(\n connection, google::cloud::Options{}\n .set\u003cgoogle::cloud::storagebatchoperations_v1::\n StorageBatchOperationsRetryPolicyOption\u003e(\n google::cloud::storagebatchoperations_v1::\n StorageBatchOperationsLimitedTimeRetryPolicy(\n std::chrono::minutes(5))\n .clone()));\n\n // You can also override the policies in a single call:\n // c3.SomeRpc(..., google::cloud::Options{}\n // .set\u003cgoogle::cloud::storagebatchoperations_v1::StorageBatchOperationsRetryPolicyOption\u003e(\n // google::cloud::storagebatchoperations_v1::StorageBatchOperationsLimitedErrorCountRetryPolicy(10).clone()));\n\nAssuming you have created a custom idempotency policy. Such as: \n\n class CustomIdempotencyPolicy\n : public google::cloud::storagebatchoperations_v1::\n StorageBatchOperationsConnectionIdempotencyPolicy {\n public:\n ~CustomIdempotencyPolicy() override = default;\n std::unique_ptr\u003cgoogle::cloud::storagebatchoperations_v1::\n StorageBatchOperationsConnectionIdempotencyPolicy\u003e\n clone() const override {\n return std::make_unique\u003cCustomIdempotencyPolicy\u003e(*this);\n }\n // Override inherited functions to define as needed.\n };"]]