diff --git a/controller/eventService/Service.go b/controller/eventService/Service.go index 7c822fc8a6b54e0d4cc07a094f9647c8f4cbd28b..3ab30a42831b3a61b6a052f5166dbc7de2810043 100644 --- a/controller/eventService/Service.go +++ b/controller/eventService/Service.go @@ -80,12 +80,17 @@ func NewEventService() (interfaces.Service, error) { } func connect(addr string) (*amqp.Connection, error) { - conn, err := amqp.Dial(addr) - if err != nil { - return nil, &customerrs.AMQPInitFailError{Action: "failed to connect to RabbitMQ", Err: err} + retries := 60 + + for i := 0; i < retries; i++ { + conn, err := amqp.Dial(addr) + if err == nil { + return conn, nil + } + time.Sleep(2 * time.Second) } - return conn, nil + return nil, &customerrs.AMQPInitFailError{Action: "failed to connect to RabbitMQ", Err: err} } // Reconnect attempts to setup a new connection to the RabbitMQ server after an disconnect.