-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceive.go
49 lines (39 loc) · 979 Bytes
/
receive.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
package main
import (
"fmt"
"time"
"github.com/streadway/amqp"
"gopkg.in/alecthomas/kingpin.v2"
)
var (
sleep = kingpin.Flag("sleep", "sleep between messages").Default("0").Int()
port = kingpin.Flag("port", "rabbitmq port").Default("5672").String()
queueName = kingpin.Flag("queue", "rabbitmq queue").Required().String()
routingKey = kingpin.Flag("routing", "routing key").Default("").String()
)
func main() {
kingpin.Parse()
conn, _ := amqp.Dial("amqp://guest:guest@localhost:" + *port)
defer conn.Close()
channel, _ := conn.Channel()
defer channel.Close()
channel.Qos(1, 0, false)
messages, _ := channel.Consume(
*queueName,
"", // consumer
false, // auto-ack
false, // exclusive
false, // no-local
false, // no-wait
nil, // args
)
forever := make(chan bool)
go func() {
for d := range messages {
fmt.Printf("%s\n", d.Body)
time.Sleep(time.Duration(*sleep) * time.Second)
d.Ack(false)
}
}()
<-forever
}