-
Notifications
You must be signed in to change notification settings - Fork 0
/
rabbitMq.go
56 lines (49 loc) · 1023 Bytes
/
rabbitMq.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
package main
import (
"fmt"
"github.com/streadway/amqp"
)
// Tutorial from https://tutorialedge.net/golang/go-rabbitmq-tutorial/
func main() {
fmt.Println("RabbitMQ + Go")
con, err := amqp.Dial("amqp://guest:guest@localhost:5672/")
if err != nil {
fmt.Println(err)
panic(1)
}
// opens a channel to RabbitMQ instance
ch, err := con.Channel()
if err != nil {
fmt.Println(err)
}
defer con.Close()
// interact with the instance and declare a queue
// we can publish and subscribe to
queue, err := ch.QueueDeclare(
"test", // name
true, // durable
false, // exclusive
false, // autoDelete
false,
nil,
)
fmt.Println(queue) // Print the queue status
if err != nil {
fmt.Println(err)
}
// Publish a message to the queue!
err = ch.Publish(
"",
"test",
false,
false,
amqp.Publishing{
ContentType: "text/plain",
Body: []byte("Muaz paling terhensem"),
},
)
if err != nil {
fmt.Println(err)
}
fmt.Println("Successfully connected to RabbitMQ instance")
}