Documentation
¶
Overview ¶
Package retry provides a retry middleware for client.
Index ¶
- Constants
- Variables
- func Always(_ context.Context, _ error, _ *client.CallOptions) (bool, error)
- func OnConnectionError(ctx context.Context, err error, options *client.CallOptions) (bool, error)
- func OnTimeoutError(ctx context.Context, err error, options *client.CallOptions) (bool, error)
- func Provide(configSection map[string]any, _ client.Type, logger log.Logger) (client.Middleware, error)
- type Config
- type Middleware
Constants ¶
const Name = "retry"
Name is the middlewares name.
Variables ¶
var ( // DefaultFunc is the default retry function. // note that returning either false or a non-nil error will result in the call not being retried. DefaultFunc = OnConnectionError // DefaultRetries is the default number of times a request is tried. // Set it to 0 to disable retries. DefaultRetries = 5 )
Functions ¶
func Always ¶
Always always retry on error. WARNING: This will retry on all errors, including business logic errors.
func OnConnectionError ¶
OnConnectionError retries a request on a 503/504 connection error. This is the default.
func OnTimeoutError ¶
OnTimeoutError retries a request on a 408 timeout error, as well as on 503/504 connection errors.
Types ¶
type Config ¶
type Config struct { // RetryFunc is the retry function. // Default is OnConnectionError. RetryFunc client.RetryFunc `json:"-" yaml:"-"` // Retries is the number of times a request is tried. // Set it to 0 to disable retries. // Default is 5. Retries int `json:"retries,omitempty" yaml:"retries,omitempty"` }
Config is the retry middleware config.
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware is the retry Middleware for client.
func (*Middleware) Request ¶
func (m *Middleware) Request( next client.MiddlewareRequestHandler, ) client.MiddlewareRequestHandler
Request wraps the original Request method or other middlewares.
func (*Middleware) Start ¶
func (m *Middleware) Start(_ context.Context) error
Start the component. E.g. connect to the broker.
func (*Middleware) Stop ¶
func (m *Middleware) Stop(_ context.Context) error
Stop the component. E.g. disconnect from the broker. The context will contain a timeout, and cancelation should be respected.
func (*Middleware) String ¶
func (m *Middleware) String() string
String returns the name of this middleware.
func (*Middleware) Type ¶
func (m *Middleware) Type() string
Type returns the component type, e.g. broker.