-
Notifications
You must be signed in to change notification settings - Fork 1
/
volta_queue.go
44 lines (35 loc) · 815 Bytes
/
volta_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
package volta
func (a *App) AddQueue(queue ...Queue) {
a.mutex.Lock()
defer a.mutex.Unlock()
if a.queues == nil {
a.queues = make(map[string]Queue)
}
for _, q := range queue {
a.queues[q.Name] = q
}
}
func (a *App) declareQueue(q Queue) error {
channel, err := a.baseConnection.Channel()
if err != nil {
return err
}
defer channel.Close()
_, err = channel.QueueDeclare(q.Name, q.Durable, q.AutoDelete, q.Exclusive, q.NoWait, nil)
if err != nil {
return err
}
return channel.QueueBind(q.Name, q.RoutingKey, q.Exchange, q.NoWait, nil)
}
func (a *App) PurgeQueue(name string, noWait bool) error {
channel, err := a.baseConnection.Channel()
if err != nil {
return err
}
defer channel.Close()
_, err = channel.QueuePurge(name, noWait)
if err != nil {
return err
}
return nil
}