-
Notifications
You must be signed in to change notification settings - Fork 3
/
deliveryInfo.go
51 lines (43 loc) · 1.1 KB
/
deliveryInfo.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
49
50
51
package bunnify
import (
amqp "github.com/rabbitmq/amqp091-go"
)
func getDeliveryInfo(queueName string, delivery amqp.Delivery) DeliveryInfo {
deliveryInfo := DeliveryInfo{
Queue: queueName,
Exchange: delivery.Exchange,
RoutingKey: delivery.RoutingKey,
}
// If routing key is empty, it is mostly due to the event being dead lettered.
// Check for the original delivery information in the headers
if delivery.RoutingKey == "" {
deaths, ok := delivery.Headers["x-death"].([]interface{})
if !ok || len(deaths) == 0 {
return deliveryInfo
}
death, ok := deaths[0].(amqp.Table)
if !ok {
return deliveryInfo
}
queue, ok := death["queue"].(string)
if !ok {
return deliveryInfo
}
deliveryInfo.Queue = queue
exchange, ok := death["exchange"].(string)
if !ok {
return deliveryInfo
}
deliveryInfo.Exchange = exchange
routingKeys, ok := death["routing-keys"].([]interface{})
if !ok || len(routingKeys) == 0 {
return deliveryInfo
}
key, ok := routingKeys[0].(string)
if !ok {
return deliveryInfo
}
deliveryInfo.RoutingKey = key
}
return deliveryInfo
}