-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.go
54 lines (47 loc) · 951 Bytes
/
queue.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
package message
import (
"github.com/bendbennett/go-bits/messaging/config"
"github.com/streadway/amqp"
)
type GetChannel func() (*amqp.Channel, error)
func ConfigureQueue(getChannel GetChannel, conf config.Messaging) error {
channel, err := getChannel()
if err != nil {
return err
}
defer channel.Close()
err = channel.ExchangeDeclare(
conf.Exchange.Name,
conf.Exchange.Kind,
conf.Exchange.Durable,
conf.Exchange.AutoDelete,
conf.Exchange.Internal,
conf.Exchange.NoWait,
conf.Exchange.Args,
)
if err != nil {
return err
}
_, err = channel.QueueDeclare(
conf.Queue.Name,
conf.Queue.Durable,
conf.Queue.AutoDelete,
conf.Queue.Exclusive,
conf.Queue.NoWait,
conf.Queue.Args,
)
if err != nil {
return err
}
err = channel.QueueBind(
conf.QueueBind.Name,
conf.QueueBind.Key,
conf.QueueBind.Exchange,
conf.QueueBind.NoWait,
conf.QueueBind.Args,
)
if err != nil {
return err
}
return nil
}