From b0d04b9a81fb7d31602ed92b35997c8712627356 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Sinha Date: Wed, 21 Nov 2018 08:37:29 +0530 Subject: [PATCH] Retry Connection for RabbitMQ (#6837) Add retries to connect to RabbitMQ 5 times with 2s interval Fixes #6807 --- pkg/event/target/amqp.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/event/target/amqp.go b/pkg/event/target/amqp.go index 67316d3f0..ffcc21a8f 100644 --- a/pkg/event/target/amqp.go +++ b/pkg/event/target/amqp.go @@ -21,6 +21,7 @@ import ( "net" "net/url" "sync" + "time" "github.com/minio/minio/pkg/event" xnet "github.com/minio/minio/pkg/net" @@ -148,9 +149,18 @@ func (target *AMQPTarget) Close() error { // NewAMQPTarget - creates new AMQP target. func NewAMQPTarget(id string, args AMQPArgs) (*AMQPTarget, error) { - conn, err := amqp.Dial(args.URL.String()) - if err != nil { - return nil, err + var conn *amqp.Connection + var err error + // Retry 5 times with time interval of 2 seconds. + for i := 1; i <= 5; i++ { + conn, err = amqp.Dial(args.URL.String()) + if err == nil { + break + } + if err != nil && i == 5 { + return nil, err + } + time.Sleep(2 * time.Second) } return &AMQPTarget{