This shows how to override the retry policies for gkehub_v1::GkeHubClient:
auto options =
google::cloud::Options{}
.set<google::cloud::gkehub_v1::
GkeHubConnectionIdempotencyPolicyOption>(
CustomIdempotencyPolicy().clone())
.set<google::cloud::gkehub_v1::GkeHubRetryPolicyOption>(
google::cloud::gkehub_v1::GkeHubLimitedErrorCountRetryPolicy(3)
.clone())
.set<google::cloud::gkehub_v1::GkeHubBackoffPolicyOption>(
google::cloud::ExponentialBackoffPolicy(
/*initial_delay=*/std::chrono::milliseconds(200),
/*maximum_delay=*/std::chrono::seconds(45),
/*scaling=*/2.0)
.clone());
auto connection = google::cloud::gkehub_v1::MakeGkeHubConnection(options);
// c1 and c2 share the same retry policies
auto c1 = google::cloud::gkehub_v1::GkeHubClient(connection);
auto c2 = google::cloud::gkehub_v1::GkeHubClient(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::gkehub_v1::GkeHubClient(
connection,
google::cloud::Options{}
.set<google::cloud::gkehub_v1::GkeHubRetryPolicyOption>(
google::cloud::gkehub_v1::GkeHubLimitedTimeRetryPolicy(
std::chrono::minutes(5))
.clone()));
// You can also override the policies in a single call:
// c3.SomeRpc(..., google::cloud::Options{}
// .set<google::cloud::gkehub_v1::GkeHubRetryPolicyOption>(
// google::cloud::gkehub_v1::GkeHubLimitedErrorCountRetryPolicy(10).clone()));
Assuming you have created a custom idempotency policy. Such as:
class CustomIdempotencyPolicy
: public google::cloud::gkehub_v1::GkeHubConnectionIdempotencyPolicy {
public:
~CustomIdempotencyPolicy() override = default;
std::unique_ptr<google::cloud::gkehub_v1::GkeHubConnectionIdempotencyPolicy>
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-09-04 UTC."],[[["\u003cp\u003eThe latest version available is 2.37.0-rc, with numerous older versions available dating back to 2.11.0.\u003c/p\u003e\n"],["\u003cp\u003eYou can override the default retry policies for \u003ccode\u003egkehub_v1::GkeHubClient\u003c/code\u003e using \u003ccode\u003eGkeHubConnectionIdempotencyPolicyOption\u003c/code\u003e, \u003ccode\u003eGkeHubRetryPolicyOption\u003c/code\u003e, and \u003ccode\u003eGkeHubBackoffPolicyOption\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eMultiple clients can share the same retry policies, as demonstrated with clients \u003ccode\u003ec1\u003c/code\u003e and \u003ccode\u003ec2\u003c/code\u003e, but individual clients can override these policies, like client \u003ccode\u003ec3\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eRetry policies can also be overridden on a per-call basis, allowing for fine-grained control over individual RPC behavior.\u003c/p\u003e\n"],["\u003cp\u003eA custom idempotency policy can be defined by inheriting from \u003ccode\u003eGkeHubConnectionIdempotencyPolicy\u003c/code\u003e, as demonstrated by the \u003ccode\u003eCustomIdempotencyPolicy\u003c/code\u003e class example.\u003c/p\u003e\n"]]],[],null,["Version latestkeyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/gkehub/latest/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.41.0](/cpp/docs/reference/gkehub/2.41.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.40.0](/cpp/docs/reference/gkehub/2.40.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.39.0](/cpp/docs/reference/gkehub/2.39.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.38.0](/cpp/docs/reference/gkehub/2.38.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.37.0](/cpp/docs/reference/gkehub/2.37.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.36.0](/cpp/docs/reference/gkehub/2.36.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.35.0](/cpp/docs/reference/gkehub/2.35.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.34.0](/cpp/docs/reference/gkehub/2.34.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.33.0](/cpp/docs/reference/gkehub/2.33.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.32.0](/cpp/docs/reference/gkehub/2.32.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.31.0](/cpp/docs/reference/gkehub/2.31.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.30.0](/cpp/docs/reference/gkehub/2.30.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.29.0](/cpp/docs/reference/gkehub/2.29.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.28.0](/cpp/docs/reference/gkehub/2.28.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.27.0](/cpp/docs/reference/gkehub/2.27.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.26.0](/cpp/docs/reference/gkehub/2.26.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.25.1](/cpp/docs/reference/gkehub/2.25.1/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.24.0](/cpp/docs/reference/gkehub/2.24.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.23.0](/cpp/docs/reference/gkehub/2.23.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.22.1](/cpp/docs/reference/gkehub/2.22.1/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.21.0](/cpp/docs/reference/gkehub/2.21.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.20.0](/cpp/docs/reference/gkehub/2.20.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.19.0](/cpp/docs/reference/gkehub/2.19.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.18.0](/cpp/docs/reference/gkehub/2.18.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.17.0](/cpp/docs/reference/gkehub/2.17.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.16.0](/cpp/docs/reference/gkehub/2.16.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.15.1](/cpp/docs/reference/gkehub/2.15.1/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.14.0](/cpp/docs/reference/gkehub/2.14.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.13.0](/cpp/docs/reference/gkehub/2.13.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.12.0](/cpp/docs/reference/gkehub/2.12.0/gkehub_v1_1_1GkeHubClient-retry-snippet)\n- [2.11.0](/cpp/docs/reference/gkehub/2.11.0/gkehub_v1_1_1GkeHubClient-retry-snippet) \n\nOverride gkehub_v1::GkeHubClient Retry Policies\n===============================================\n\nThis shows how to override the retry policies for gkehub_v1::GkeHubClient: \n\n auto options =\n google::cloud::Options{}\n .set\u003cgoogle::cloud::gkehub_v1::\n GkeHubConnectionIdempotencyPolicyOption\u003e(\n CustomIdempotencyPolicy().clone())\n .set\u003cgoogle::cloud::gkehub_v1::GkeHubRetryPolicyOption\u003e(\n google::cloud::gkehub_v1::GkeHubLimitedErrorCountRetryPolicy(3)\n .clone())\n .set\u003cgoogle::cloud::gkehub_v1::GkeHubBackoffPolicyOption\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::gkehub_v1::MakeGkeHubConnection(options);\n\n // c1 and c2 share the same retry policies\n auto c1 = google::cloud::gkehub_v1::GkeHubClient(connection);\n auto c2 = google::cloud::gkehub_v1::GkeHubClient(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::gkehub_v1::GkeHubClient(\n connection,\n google::cloud::Options{}\n .set\u003cgoogle::cloud::gkehub_v1::GkeHubRetryPolicyOption\u003e(\n google::cloud::gkehub_v1::GkeHubLimitedTimeRetryPolicy(\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::gkehub_v1::GkeHubRetryPolicyOption\u003e(\n // google::cloud::gkehub_v1::GkeHubLimitedErrorCountRetryPolicy(10).clone()));\n\nAssuming you have created a custom idempotency policy. Such as: \n\n class CustomIdempotencyPolicy\n : public google::cloud::gkehub_v1::GkeHubConnectionIdempotencyPolicy {\n public:\n ~CustomIdempotencyPolicy() override = default;\n std::unique_ptr\u003cgoogle::cloud::gkehub_v1::GkeHubConnectionIdempotencyPolicy\u003e\n clone() const override {\n return std::make_unique\u003cCustomIdempotencyPolicy\u003e(*this);\n }\n // Override inherited functions to define as needed.\n };"]]