When a service call fails, we can allow the framework to automatically retry a few times, which can improve the success rate of requests seen by users. In failover cluster mode, dubbo-go supports automatic retries.
This example demonstrates how to configure the retry function when a client-side call fails. Full example source code
When creating a client using client.NewClient()
, you can set the retry count using client.WithClientRetries()
method.
Alternatively, you can set the service-level timeout using client.WithRequestTimeout()
(the following configuration applies to service svc
).
You can also specify the retry count at the time of the call using client.WithCallRetries()
.
From top to bottom, the priority of the above three methods increases, with client.WithCallRetries()
having the highest priority.
Source file path: dubbo-go-sample/retry/proto/greet.proto
The Greet
method responds directly, while the GreetRetry
method simulates retries.
The client file creates a client, sets the retry count to 3, and makes requests to Greet
and GreetRetry
, observing the server log output.
Start the server first, then start the client. When accessing GreetRetry
, observe the server log output showing the retry count.