-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfigure.go
63 lines (49 loc) · 1.64 KB
/
configure.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
52
53
54
55
56
57
58
59
60
61
62
63
package tackle
import rabbit "github.com/rabbitmq/amqp091-go"
const (
DeadLetterTimeout = 604_800_000 // 1 week
)
func ConfigureExchanges(channel *rabbit.Channel, options *Options) error {
remoteExch := options.RemoteExchange
serviceExch := options.GetServiceExchangeName()
err := channel.ExchangeDeclare(remoteExch, "direct", Durable, AutoDeleted, Internal, NoWait, nil)
if err != nil {
return err
}
err = channel.ExchangeDeclare(serviceExch, "direct", Durable, AutoDeleted, Internal, NoWait, nil)
if err != nil {
return err
}
err = channel.ExchangeBind(serviceExch, options.RoutingKey, options.RemoteExchange, NoWait, nil)
if err != nil {
return err
}
return nil
}
func ConfigureQueues(channel *rabbit.Channel, options *Options) error {
queueOptions := map[string]interface{}{
"x-message-ttl": DeadLetterTimeout,
}
retryQueueOptions := map[string]interface{}{
"x-message-ttl": options.GetRetryDelay() * 1000,
"x-dead-letter-exchange": options.GetServiceExchangeName(),
"x-dead-letter-routing-key": options.RoutingKey,
}
_, err := channel.QueueDeclare(options.GetQueueName(), Durable, AutoDeleted, Exclusive, NoWait, nil)
if err != nil {
return err
}
_, err = channel.QueueDeclare(options.GetDeadQueueName(), Durable, AutoDeleted, Exclusive, NoWait, queueOptions)
if err != nil {
return err
}
_, err = channel.QueueDeclare(options.GetDelayQueueName(), Durable, AutoDeleted, Exclusive, NoWait, retryQueueOptions)
if err != nil {
return err
}
err = channel.QueueBind(options.GetQueueName(), options.RoutingKey, options.GetServiceExchangeName(), NoWait, nil)
if err != nil {
return err
}
return nil
}