-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
48 lines (38 loc) · 819 Bytes
/
utils.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
package goqueue
import (
"fmt"
"github.com/streadway/amqp"
"time"
)
const RetryHeader = "x-goqueue-retry"
func getRetry(headers amqp.Table) int {
// Default zero retry
if headers == nil || len(headers) == 0 {
return 0
}
switch retry := headers[RetryHeader].(type) {
case int:
return retry
case int32:
return int(retry)
case int64:
return int(retry)
default:
return 0
}
}
func getExchangeName(consumerName string, retry int) string {
if retry == -1 {
return consumerName
}
return fmt.Sprintf("%s__retry", consumerName)
}
func getQueueName(consumerName string, retry int, intervals []time.Duration) string {
if retry == -1 {
return consumerName
}
if retry > len(intervals)-1 {
return ""
}
return fmt.Sprintf("%s__retry__%ds", consumerName, int(intervals[retry].Seconds()))
}