Craig Tiller
dbb5164ac7
Closes #37820 PiperOrigin-RevId: 682352913 |
2 months ago | |
---|---|---|
.. | ||
BUILD |
…
|
|
CMakeLists.txt | [Build] Bumped the minimum version of cmake (#37702) | 2 months ago |
README.md |
…
|
|
client.cc | [clang-format] Remove custom clang-format rules for include ordering (#37820) | 2 months ago |
server.cc | [clang-format] Remove custom clang-format rules for include ordering (#37820) | 2 months ago |
README.md
Retry
This example shows how to enable and configure retry on gRPC clients.
Documentation
gRFC for client-side retry support
Try it
This example includes a service implementation that fails requests three times with status
code Unavailable
, then passes the fourth. The client is configured to make four retry attempts
when receiving an Unavailable
status code.
First start the server:
$ ./server
Then run the client:
$ ./client
Expected server output:
Server listening on 0.0.0.0:50052
return UNAVAILABLE
return UNAVAILABLE
return UNAVAILABLE
return OK
Expected client output:
Greeter received: Hello world
Usage
Define your retry policy
Retry is enabled via the service config, which can be provided by the name resolver or a GRPC_ARG_SERVICE_CONFIG channel argument. In the below config, we set retry policy for the "helloworld.Greeter" service.
maxAttempts
: how many times to attempt the RPC before failing.
initialBackoff
, maxBackoff
, backoffMultiplier
: configures delay between attempts.
retryableStatusCodes
: Retry only when receiving these status codes.
constexpr absl::string_view kRetryPolicy =
"{\"methodConfig\" : [{"
" \"name\" : [{\"service\": \"helloworld.Greeter\"}],"
" \"waitForReady\": true,"
" \"retryPolicy\": {"
" \"maxAttempts\": 4,"
" \"initialBackoff\": \"1s\","
" \"maxBackoff\": \"120s\","
" \"backoffMultiplier\": 1.0,"
" \"retryableStatusCodes\": [\"UNAVAILABLE\"]"
" }"
"}]}";