mirror of
https://github.com/minio/minio.git
synced 2025-01-26 22:23:15 -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"
|
||||||
"net/url"
|
"net/url"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/event"
|
"github.com/minio/minio/pkg/event"
|
||||||
xnet "github.com/minio/minio/pkg/net"
|
xnet "github.com/minio/minio/pkg/net"
|
||||||
@ -148,10 +149,19 @@ func (target *AMQPTarget) Close() error {
|
|||||||
|
|
||||||
// NewAMQPTarget - creates new AMQP target.
|
// NewAMQPTarget - creates new AMQP target.
|
||||||
func NewAMQPTarget(id string, args AMQPArgs) (*AMQPTarget, error) {
|
func NewAMQPTarget(id string, args AMQPArgs) (*AMQPTarget, error) {
|
||||||
conn, err := amqp.Dial(args.URL.String())
|
var conn *amqp.Connection
|
||||||
if err != nil {
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
return &AMQPTarget{
|
return &AMQPTarget{
|
||||||
id: event.TargetID{ID: id, Name: "amqp"},
|
id: event.TargetID{ID: id, Name: "amqp"},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user