-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdial_utils.go
More file actions
35 lines (29 loc) · 866 Bytes
/
dial_utils.go
File metadata and controls
35 lines (29 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package artifacts
import (
"log"
"time"
amqp "github.com/rabbitmq/amqp091-go"
)
var maxRetryCount = 12
// dialRMQ creates a connection with RabbiMQ and stores the amqp connection
// object for usage by other functions
func dialRMQ(brokerUrl string) (rmqConn *amqp.Connection, err error) {
retryTimeout := 1
retryCount := 0
var retryDuration time.Duration
for {
if rmqConn, err = amqp.Dial(brokerUrl); err == nil {
log.Println("Successfully reconnected to RabbitMQ")
return rmqConn, nil
}
log.Printf("Failed to connect to RMQ, Error: %v", err)
if retryCount > maxRetryCount {
return nil, err
}
// Wait for retrying in time intervals based on fibonacci series
retryTimeout, retryDuration = GetRetryTimeout(retryTimeout)
log.Printf("Retrying connection in %d seconds", retryTimeout)
time.Sleep(retryDuration)
retryCount++
}
}