Add retries
This commit is contained in:
@@ -16,6 +16,7 @@ type Options struct {
|
||||
Selector selector.Selector
|
||||
Transport transport.Transport
|
||||
Wrappers []Wrapper
|
||||
Retries int
|
||||
|
||||
// Other options to be used by client implementations
|
||||
Options map[string]string
|
||||
@@ -40,6 +41,44 @@ type RequestOptions struct {
|
||||
Options map[string]string
|
||||
}
|
||||
|
||||
func newOptions(options ...Option) Options {
|
||||
opts := Options{
|
||||
Codecs: make(map[string]codec.NewCodec),
|
||||
}
|
||||
|
||||
for _, o := range options {
|
||||
o(&opts)
|
||||
}
|
||||
|
||||
if opts.Retries == 0 {
|
||||
opts.Retries = 1
|
||||
}
|
||||
|
||||
if len(opts.ContentType) == 0 {
|
||||
opts.ContentType = defaultContentType
|
||||
}
|
||||
|
||||
if opts.Broker == nil {
|
||||
opts.Broker = broker.DefaultBroker
|
||||
}
|
||||
|
||||
if opts.Registry == nil {
|
||||
opts.Registry = registry.DefaultRegistry
|
||||
}
|
||||
|
||||
if opts.Selector == nil {
|
||||
opts.Selector = selector.NewSelector(
|
||||
selector.Registry(opts.Registry),
|
||||
)
|
||||
}
|
||||
|
||||
if opts.Transport == nil {
|
||||
opts.Transport = transport.DefaultTransport
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
// Broker to be used for pub/sub
|
||||
func Broker(b broker.Broker) Option {
|
||||
return func(o *Options) {
|
||||
@@ -89,6 +128,13 @@ func Wrap(w Wrapper) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// Number of retries when making the request
|
||||
func Retries(i int) Option {
|
||||
return func(o *Options) {
|
||||
o.Retries = i
|
||||
}
|
||||
}
|
||||
|
||||
// Call Options
|
||||
|
||||
func WithSelectOption(so selector.SelectOption) CallOption {
|
||||
|
Reference in New Issue
Block a user