This shows how to override the retry policies for contentwarehouse_v1::DocumentServiceClient:
auto options = google::cloud::Options{}
.set<google::cloud::contentwarehouse_v1::
DocumentServiceConnectionIdempotencyPolicyOption>(
CustomIdempotencyPolicy().clone())
.set<google::cloud::contentwarehouse_v1::
DocumentServiceRetryPolicyOption>(
google::cloud::contentwarehouse_v1::
DocumentServiceLimitedErrorCountRetryPolicy(3)
.clone())
.set<google::cloud::contentwarehouse_v1::
DocumentServiceBackoffPolicyOption>(
google::cloud::ExponentialBackoffPolicy(
/*initial_delay=*/std::chrono::milliseconds(200),
/*maximum_delay=*/std::chrono::seconds(45),
/*scaling=*/2.0)
.clone());
auto connection =
google::cloud::contentwarehouse_v1::MakeDocumentServiceConnection(
options);
// c1 and c2 share the same retry policies
auto c1 =
google::cloud::contentwarehouse_v1::DocumentServiceClient(connection);
auto c2 =
google::cloud::contentwarehouse_v1::DocumentServiceClient(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::contentwarehouse_v1::DocumentServiceClient(
connection,
google::cloud::Options{}
.set<google::cloud::contentwarehouse_v1::
DocumentServiceRetryPolicyOption>(
google::cloud::contentwarehouse_v1::
DocumentServiceLimitedTimeRetryPolicy(std::chrono::minutes(5))
.clone()));
// You can also override the policies in a single call:
// c3.SomeRpc(..., google::cloud::Options{}
// .set<google::cloud::contentwarehouse_v1::DocumentServiceRetryPolicyOption>(
// google::cloud::contentwarehouse_v1::DocumentServiceLimitedErrorCountRetryPolicy(10).clone()));
Assuming you have created a custom idempotency policy. Such as:
class CustomIdempotencyPolicy : public google::cloud::contentwarehouse_v1::
DocumentServiceConnectionIdempotencyPolicy {
public:
~CustomIdempotencyPolicy() override = default;
std::unique_ptr<google::cloud::contentwarehouse_v1::
DocumentServiceConnectionIdempotencyPolicy>
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\u003eThis document provides a guide on how to override retry policies for \u003ccode\u003econtentwarehouse_v1::DocumentServiceClient\u003c/code\u003e in C++.\u003c/p\u003e\n"],["\u003cp\u003eThe latest release candidate version is 2.37.0-rc, and a list of prior versions ranging from 2.36.0 to 2.12.0 is provided, each linked to its respective documentation.\u003c/p\u003e\n"],["\u003cp\u003eRetry policies can be overridden globally for a client or on a per-call basis using \u003ccode\u003egoogle::cloud::Options\u003c/code\u003e, allowing for customized error handling and backoff strategies.\u003c/p\u003e\n"],["\u003cp\u003eThe example demonstrates how to set custom retry policies, including a custom \u003ccode\u003eIdempotencyPolicy\u003c/code\u003e, \u003ccode\u003eRetryPolicy\u003c/code\u003e (using error count and time limitations), and \u003ccode\u003eBackoffPolicy\u003c/code\u003e (using exponential backoff).\u003c/p\u003e\n"],["\u003cp\u003eThe code shows that multiple clients can share the same retry policies, but also that each of them can have their own modified custom retry policies, or each call can use its own retry policies.\u003c/p\u003e\n"]]],[],null,["Version 2.35.0keyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/contentwarehouse/latest/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.41.0](/cpp/docs/reference/contentwarehouse/2.41.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.40.0](/cpp/docs/reference/contentwarehouse/2.40.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.39.0](/cpp/docs/reference/contentwarehouse/2.39.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.38.0](/cpp/docs/reference/contentwarehouse/2.38.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.37.0](/cpp/docs/reference/contentwarehouse/2.37.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.36.0](/cpp/docs/reference/contentwarehouse/2.36.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.35.0](/cpp/docs/reference/contentwarehouse/2.35.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.34.0](/cpp/docs/reference/contentwarehouse/2.34.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.33.0](/cpp/docs/reference/contentwarehouse/2.33.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.32.0](/cpp/docs/reference/contentwarehouse/2.32.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.31.0](/cpp/docs/reference/contentwarehouse/2.31.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.30.0](/cpp/docs/reference/contentwarehouse/2.30.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.29.0](/cpp/docs/reference/contentwarehouse/2.29.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.28.0](/cpp/docs/reference/contentwarehouse/2.28.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.27.0](/cpp/docs/reference/contentwarehouse/2.27.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.26.0](/cpp/docs/reference/contentwarehouse/2.26.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.25.1](/cpp/docs/reference/contentwarehouse/2.25.1/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.24.0](/cpp/docs/reference/contentwarehouse/2.24.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.23.0](/cpp/docs/reference/contentwarehouse/2.23.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.22.1](/cpp/docs/reference/contentwarehouse/2.22.1/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.21.0](/cpp/docs/reference/contentwarehouse/2.21.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.20.0](/cpp/docs/reference/contentwarehouse/2.20.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.19.0](/cpp/docs/reference/contentwarehouse/2.19.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.18.0](/cpp/docs/reference/contentwarehouse/2.18.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.17.0](/cpp/docs/reference/contentwarehouse/2.17.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.16.0](/cpp/docs/reference/contentwarehouse/2.16.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.15.1](/cpp/docs/reference/contentwarehouse/2.15.1/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.14.0](/cpp/docs/reference/contentwarehouse/2.14.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.13.0](/cpp/docs/reference/contentwarehouse/2.13.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet)\n- [2.12.0](/cpp/docs/reference/contentwarehouse/2.12.0/contentwarehouse_v1_1_1DocumentServiceClient-retry-snippet) \n\nOverride contentwarehouse_v1::DocumentServiceClient Retry Policies\n==================================================================\n\nThis shows how to override the retry policies for contentwarehouse_v1::DocumentServiceClient: \n\n auto options = google::cloud::Options{}\n .set\u003cgoogle::cloud::contentwarehouse_v1::\n DocumentServiceConnectionIdempotencyPolicyOption\u003e(\n CustomIdempotencyPolicy().clone())\n .set\u003cgoogle::cloud::contentwarehouse_v1::\n DocumentServiceRetryPolicyOption\u003e(\n google::cloud::contentwarehouse_v1::\n DocumentServiceLimitedErrorCountRetryPolicy(3)\n .clone())\n .set\u003cgoogle::cloud::contentwarehouse_v1::\n DocumentServiceBackoffPolicyOption\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::contentwarehouse_v1::MakeDocumentServiceConnection(\n options);\n\n // c1 and c2 share the same retry policies\n auto c1 =\n google::cloud::contentwarehouse_v1::DocumentServiceClient(connection);\n auto c2 =\n google::cloud::contentwarehouse_v1::DocumentServiceClient(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::contentwarehouse_v1::DocumentServiceClient(\n connection,\n google::cloud::Options{}\n .set\u003cgoogle::cloud::contentwarehouse_v1::\n DocumentServiceRetryPolicyOption\u003e(\n google::cloud::contentwarehouse_v1::\n DocumentServiceLimitedTimeRetryPolicy(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::contentwarehouse_v1::DocumentServiceRetryPolicyOption\u003e(\n // google::cloud::contentwarehouse_v1::DocumentServiceLimitedErrorCountRetryPolicy(10).clone()));\n\nAssuming you have created a custom idempotency policy. Such as: \n\n class CustomIdempotencyPolicy : public google::cloud::contentwarehouse_v1::\n DocumentServiceConnectionIdempotencyPolicy {\n public:\n ~CustomIdempotencyPolicy() override = default;\n std::unique_ptr\u003cgoogle::cloud::contentwarehouse_v1::\n DocumentServiceConnectionIdempotencyPolicy\u003e\n clone() const override {\n return std::make_unique\u003cCustomIdempotencyPolicy\u003e(*this);\n }\n // Override inherited functions to define as needed.\n };"]]