-
Notifications
You must be signed in to change notification settings - Fork 0
/
mensageria.go
52 lines (47 loc) · 910 Bytes
/
mensageria.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
package main
import (
"log"
"github.com/streadway/amqp"
)
func publishMail(userName string) {
// Open connection with RabbitMQ server
conn, err := amqp.Dial("amqp://guest:guest@rabbitmq/")
if err != nil {
println()
log.Fatalf("fail to dial to rabbitmq: %v", err)
}
defer conn.Close()
// Open a channel to RabbitMQ instance
ch, err := conn.Channel()
if err != nil {
log.Fatalf("fail to create channel: %v", err)
}
defer ch.Close()
// Declare a queue to be used
q, err := ch.QueueDeclare(
"MailQueue",
false,
false,
false,
false,
nil,
)
if err != nil {
log.Fatalf("fail to declare queue: %v", err)
log.Fatal(q)
}
// Publish a message to the queue
err = ch.Publish(
"",
"MailQueue",
false,
false,
amqp.Publishing{
ContentType: "text/plain",
Body: []byte(userName),
},
)
if err != nil {
log.Fatalf("fail to publish message: %v", err)
}
}