-
Notifications
You must be signed in to change notification settings - Fork 0
/
amqp09.go
53 lines (42 loc) · 1.15 KB
/
amqp09.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
package amqp09
import (
"fmt"
"github.com/streadway/amqp"
"log"
)
func DeclareExchange(amqpUri string, exchange string, exchangeType string, queueName string) {
conn, err := amqp.Dial(amqpUri)
if err != nil {
panic(err)
}
defer conn.Close()
channel, err := conn.Channel()
if err != nil {
panic(err)
}
defer channel.Close()
if err = channel.ExchangeDeclare(
exchange, // name of the Exchange
exchangeType, // type
true, // durable
false, // delete when complete
false, // internal
false, // noWait
nil, // arguments
); err != nil {
panic(fmt.Errorf("exchange Declare: %source", err))
}
queue, err := channel.QueueDeclare(
queueName, // name of the queue
true, // durable
false, // delete when unused
false, // exclusive
false, // noWait
nil, // arguments
)
if err != nil {
panic(fmt.Errorf("Queue Declare: %source", err))
}
log.Printf("Declared %v exchange %q and Queue %q (%d messages, %d consumers)",
exchangeType, exchange, queue.Name, queue.Messages, queue.Consumers)
}