This shows how to override the retry policies for batch_v1::BatchServiceClient:
auto options =
google::cloud::Options{}
.set<google::cloud::batch_v1::
BatchServiceConnectionIdempotencyPolicyOption>(
CustomIdempotencyPolicy().clone())
.set<google::cloud::batch_v1::BatchServiceRetryPolicyOption>(
google::cloud::batch_v1::BatchServiceLimitedErrorCountRetryPolicy(
3)
.clone())
.set<google::cloud::batch_v1::BatchServiceBackoffPolicyOption>(
google::cloud::ExponentialBackoffPolicy(
/*initial_delay=*/std::chrono::milliseconds(200),
/*maximum_delay=*/std::chrono::seconds(45),
/*scaling=*/2.0)
.clone());
auto connection =
google::cloud::batch_v1::MakeBatchServiceConnection(options);
// c1 and c2 share the same retry policies
auto c1 = google::cloud::batch_v1::BatchServiceClient(connection);
auto c2 = google::cloud::batch_v1::BatchServiceClient(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::batch_v1::BatchServiceClient(
connection,
google::cloud::Options{}
.set<google::cloud::batch_v1::BatchServiceRetryPolicyOption>(
google::cloud::batch_v1::BatchServiceLimitedTimeRetryPolicy(
std::chrono::minutes(5))
.clone()));
// You can also override the policies in a single call:
// c3.SomeRpc(..., google::cloud::Options{}
// .set<google::cloud::batch_v1::BatchServiceRetryPolicyOption>(
// google::cloud::batch_v1::BatchServiceLimitedErrorCountRetryPolicy(10).clone()));
Assuming you have created a custom idempotency policy. Such as:
class CustomIdempotencyPolicy
: public google::cloud::batch_v1::BatchServiceConnectionIdempotencyPolicy {
public:
~CustomIdempotencyPolicy() override = default;
std::unique_ptr<
google::cloud::batch_v1::BatchServiceConnectionIdempotencyPolicy>
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"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[[["\u003cp\u003eThe content provides a list of available versions for \u003ccode\u003ebatch_v1::BatchServiceClient\u003c/code\u003e, ranging from version 2.11.0 up to the latest release candidate 2.37.0-rc, and version 2.21.0 is indicated as the current focus in the page title.\u003c/p\u003e\n"],["\u003cp\u003eIt details how to override the default retry policies for \u003ccode\u003ebatch_v1::BatchServiceClient\u003c/code\u003e, including setting custom retry and backoff policies with examples of \u003ccode\u003eBatchServiceLimitedErrorCountRetryPolicy\u003c/code\u003e and \u003ccode\u003eExponentialBackoffPolicy\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe document explains that multiple clients can share the same retry policies when created with the same connection, but individual clients can override these policies either during client creation or for a single call using \u003ccode\u003egoogle::cloud::Options\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eIt showcases how to create and utilize a custom idempotency policy, \u003ccode\u003eCustomIdempotencyPolicy\u003c/code\u003e, by inheriting from \u003ccode\u003eBatchServiceConnectionIdempotencyPolicy\u003c/code\u003e and overriding specific functions as needed.\u003c/p\u003e\n"]]],[],null,["Version 2.21.0keyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/batch/latest/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.41.0](/cpp/docs/reference/batch/2.41.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.40.0](/cpp/docs/reference/batch/2.40.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.39.0](/cpp/docs/reference/batch/2.39.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.38.0](/cpp/docs/reference/batch/2.38.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.37.0](/cpp/docs/reference/batch/2.37.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.36.0](/cpp/docs/reference/batch/2.36.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.35.0](/cpp/docs/reference/batch/2.35.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.34.0](/cpp/docs/reference/batch/2.34.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.33.0](/cpp/docs/reference/batch/2.33.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.32.0](/cpp/docs/reference/batch/2.32.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.31.0](/cpp/docs/reference/batch/2.31.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.30.0](/cpp/docs/reference/batch/2.30.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.29.0](/cpp/docs/reference/batch/2.29.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.28.0](/cpp/docs/reference/batch/2.28.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.27.0](/cpp/docs/reference/batch/2.27.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.26.0](/cpp/docs/reference/batch/2.26.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.25.1](/cpp/docs/reference/batch/2.25.1/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.24.0](/cpp/docs/reference/batch/2.24.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.23.0](/cpp/docs/reference/batch/2.23.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.22.1](/cpp/docs/reference/batch/2.22.1/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.21.0](/cpp/docs/reference/batch/2.21.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.20.0](/cpp/docs/reference/batch/2.20.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.19.0](/cpp/docs/reference/batch/2.19.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.18.0](/cpp/docs/reference/batch/2.18.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.17.0](/cpp/docs/reference/batch/2.17.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.16.0](/cpp/docs/reference/batch/2.16.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.15.1](/cpp/docs/reference/batch/2.15.1/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.14.0](/cpp/docs/reference/batch/2.14.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.13.0](/cpp/docs/reference/batch/2.13.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.12.0](/cpp/docs/reference/batch/2.12.0/batch_v1_1_1BatchServiceClient-retry-snippet)\n- [2.11.0](/cpp/docs/reference/batch/2.11.0/batch_v1_1_1BatchServiceClient-retry-snippet) \n\nOverride batch_v1::BatchServiceClient Retry Policies\n====================================================\n\nThis shows how to override the retry policies for batch_v1::BatchServiceClient: \n\n auto options =\n google::cloud::Options{}\n .set\u003cgoogle::cloud::batch_v1::\n BatchServiceConnectionIdempotencyPolicyOption\u003e(\n CustomIdempotencyPolicy().clone())\n .set\u003cgoogle::cloud::batch_v1::BatchServiceRetryPolicyOption\u003e(\n google::cloud::batch_v1::BatchServiceLimitedErrorCountRetryPolicy(\n 3)\n .clone())\n .set\u003cgoogle::cloud::batch_v1::BatchServiceBackoffPolicyOption\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 =\n google::cloud::batch_v1::MakeBatchServiceConnection(options);\n\n // c1 and c2 share the same retry policies\n auto c1 = google::cloud::batch_v1::BatchServiceClient(connection);\n auto c2 = google::cloud::batch_v1::BatchServiceClient(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 = google::cloud::batch_v1::BatchServiceClient(\n connection,\n google::cloud::Options{}\n .set\u003cgoogle::cloud::batch_v1::BatchServiceRetryPolicyOption\u003e(\n google::cloud::batch_v1::BatchServiceLimitedTimeRetryPolicy(\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::batch_v1::BatchServiceRetryPolicyOption\u003e(\n // google::cloud::batch_v1::BatchServiceLimitedErrorCountRetryPolicy(10).clone()));\n\nAssuming you have created a custom idempotency policy. Such as: \n\n class CustomIdempotencyPolicy\n : public google::cloud::batch_v1::BatchServiceConnectionIdempotencyPolicy {\n public:\n ~CustomIdempotencyPolicy() override = default;\n std::unique_ptr\u003c\n google::cloud::batch_v1::BatchServiceConnectionIdempotencyPolicy\u003e\n clone() const override {\n return std::make_unique\u003cCustomIdempotencyPolicy\u003e(*this);\n }\n // Override inherited functions to define as needed.\n };"]]