diff --git a/client.go b/client.go index 1d036ae..801c859 100644 --- a/client.go +++ b/client.go @@ -3,6 +3,7 @@ package amqp import ( "fmt" "context" + "time" "sync" "github.com/streadway/amqp" @@ -49,7 +50,17 @@ func (f backendFactory) New(remote *config.Backend) proxy.Proxy { } func (f backendFactory) newChannel(path string) (*amqp.Channel, closer, error) { - conn, err := amqp.Dial(path) + var ( + conn *amqp.Connection + err error + ) + for { + conn, err = amqp.Dial(path) + if err == nil { + break + } + time.Sleep(time.Duration(3) * time.Second) + } if err != nil { return nil, nopCloser, err } diff --git a/rpc.go b/rpc.go index 0f3dac1..f057bda 100644 --- a/rpc.go +++ b/rpc.go @@ -107,11 +107,8 @@ func (f backendFactory) initRpcChannel(ctx context.Context, cfg *rpcCfg, dns str if !ok { break } - for { - time.Sleep(time.Duration(3) * time.Second) - if err := f.initRpcChannel(ctx, cfg, dns, rch); err == nil { - break - } + if err := f.initRpcChannel(ctx, cfg, dns, rch); err == nil { + break } case reply, ok := <-replies: if !ok {