-
Notifications
You must be signed in to change notification settings - Fork 1
/
producer.go
59 lines (51 loc) · 1.15 KB
/
producer.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
package conejo
import (
//"errors"
"github.com/streadway/amqp"
//"log"
)
func Publish(conn *amqp.Connection, queue Queue, exchange Exchange, body string) error {
channel, err := createChannel(conn)
if err != nil {
return err
}
channel.Confirm(false)
defer channel.Close()
//ack, nack := channel.NotifyConfirm(make(chan uint64, 1), make(chan uint64, 1))
err = declareExchange(exchange, channel)
if err != nil {
return err
}
err = declareQueue(queue, channel)
if err != nil {
return err
}
err = channel.QueueBind(
queue.Name, // queue name
queue.Name, // @TODO - FIX ME!!!
exchange.Name, // exchange
false,
nil,
)
if err != nil {
return err
}
err = channel.Publish(
exchange.Name, // publish to an exchange
queue.Name, // routing to 0 or more queues
false, // mandatory
false, // immediate
amqp.Publishing{
Headers: amqp.Table{},
ContentType: "text/plain",
ContentEncoding: "",
Body: []byte(body),
DeliveryMode: amqp.Transient, // 1=non-persistent, 2=persistent
Priority: 0, // 0-9
},
)
if err != nil {
return err
}
return nil
}