mirror of
https://github.com/minio/minio.git
synced 2025-01-24 13:13:16 -05:00
Retry Connection for RabbitMQ (#6837)
Add retries to connect to RabbitMQ 5 times with 2s interval Fixes #6807
This commit is contained in:
parent
a9de303d8b
commit
b0d04b9a81
@ -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{
|
||||
|
Loading…
x
Reference in New Issue
Block a user