-
Notifications
You must be signed in to change notification settings - Fork 0
/
rabbitmq.go
46 lines (41 loc) · 1006 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
package main
import (
"fmt"
amqp "github.com/rabbitmq/amqp091-go"
"github.com/rs/zerolog/log"
)
func SetupRabbitMq(mqUsername string, mqPassword string, mqEndpoint string) (<-chan amqp.Delivery, *amqp.Connection, error) {
conn, err := amqp.Dial(fmt.Sprintf("amqp://%s:%s@%s/", mqUsername, mqPassword, mqEndpoint))
failOnError(err, "Failed to connect to RabbitMQ")
ch, err := conn.Channel()
if err != nil {
log.Error().Err(err).Msg("Failed to open a channel")
return nil, nil, err
}
q, err := ch.QueueDeclare(
"images", // name
true, // durable
false, // delete when unused
false, // exclusive
false, // no-wait
nil, // arguments
)
if err != nil {
log.Error().Err(err).Msg("Failed to declare queue")
return nil, nil, err
}
msgs, err := ch.Consume(
q.Name,
"irmgard-worker",
false,
false,
false,
false,
nil,
)
if err != nil {
log.Error().Err(err).Msg("Failed to register consumer")
return nil, nil, err
}
return msgs, conn, nil
}