-
Notifications
You must be signed in to change notification settings - Fork 8
/
rabbit_init.go
67 lines (59 loc) · 1.25 KB
/
rabbit_init.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
64
65
66
67
package amqpjobs
import (
"github.com/roadrunner-server/errors"
)
func (d *Driver) init() error {
const op = errors.Op("jobs_plugin_amqp_init")
// Channel opens a unique, concurrent server channel to process the bulk of AMQP
// messages. Any error from methods on this receiver will render the receiver
// invalid and a new Channel should be opened.
channel, err := d.conn.Channel()
if err != nil {
return errors.E(op, err)
}
// declare an exchange (idempotent operation)
err = channel.ExchangeDeclare(
d.exchangeName,
d.exchangeType,
d.exchangeDurable,
d.exchangeAutoDelete,
false,
false,
nil,
)
if err != nil {
return errors.E(op, err)
}
return channel.Close()
}
func (d *Driver) declareQueue() error {
const op = errors.Op("jobs_plugin_rmq_queue_declare")
channel, err := d.conn.Channel()
if err != nil {
return errors.E(op, err)
}
// verify or declare a queue
q, err := channel.QueueDeclare(
d.queue,
d.durable,
d.queueAutoDelete,
d.exclusive,
false,
d.queueHeaders,
)
if err != nil {
return errors.E(op, err)
}
// bind queue to the exchange
err = channel.QueueBind(
q.Name,
d.routingKey,
d.exchangeName,
false,
nil,
)
if err != nil {
return errors.E(op, err)
}
return channel.Close()
}