Add grpc retry (#1160)
* Add grpc retry * Update grpc retry * Add tests * Fix a bug * Add api && some tests * Add comment * Add double check * Add server retry quota * Update optimize code * Fix bug * Update optimize code * Update optimize code * Fix bug
This commit is contained in:
@@ -31,6 +31,7 @@ type (
|
||||
// A ClientOptions is a client options.
|
||||
ClientOptions struct {
|
||||
Timeout time.Duration
|
||||
Retry bool
|
||||
DialOptions []grpc.DialOption
|
||||
}
|
||||
|
||||
@@ -72,6 +73,7 @@ func (c *client) buildDialOptions(opts ...ClientOption) []grpc.DialOption {
|
||||
clientinterceptors.PrometheusInterceptor,
|
||||
clientinterceptors.BreakerInterceptor,
|
||||
clientinterceptors.TimeoutInterceptor(cliOpts.Timeout),
|
||||
clientinterceptors.RetryInterceptor(cliOpts.Retry),
|
||||
),
|
||||
WithStreamClientInterceptors(
|
||||
clientinterceptors.StreamTracingInterceptor,
|
||||
@@ -117,6 +119,13 @@ func WithTimeout(timeout time.Duration) ClientOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithRetry returns a func to customize a ClientOptions with auto retry.
|
||||
func WithRetry() ClientOption {
|
||||
return func(options *ClientOptions) {
|
||||
options.Retry = true
|
||||
}
|
||||
}
|
||||
|
||||
// WithUnaryClientInterceptor returns a func to customize a ClientOptions with given interceptor.
|
||||
func WithUnaryClientInterceptor(interceptor grpc.UnaryClientInterceptor) ClientOption {
|
||||
return func(options *ClientOptions) {
|
||||
|
||||
Reference in New Issue
Block a user