Add retries

This commit is contained in:
Asim
2016-01-02 23:16:15 +00:00
parent b11e5789fe
commit 1037663acf
2 changed files with 89 additions and 54 deletions

View File

@@ -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 {