about summary refs log tree commit diff
path: root/src/payload-processor/processor/processor.go
blob: 3eb089b8cc664eeb97efac1236d7e7d0ce6108f7 (plain) (blame)
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
package processor

import (
	"log"

	amqp "github.com/rabbitmq/amqp091-go"
)

type Processor struct {
	ch        *amqp.Channel
	queueName string
}

func NewProcessor(ch *amqp.Channel, queueName string) Processor {
	log.Println("Created processor")
	return Processor{
		ch:        ch,
		queueName: queueName,
	}
}

func (p Processor) ProcessMessages() {
	msgs, err := p.ch.Consume(
		p.queueName, // queue
		"",          // consumer
		true,        // auto-ack
		false,       // exclusive
		false,       // no-local
		false,       // no-wait
		nil,         // args
	)
	if err != nil {
		log.Fatal("Failed to register a consumer:", err)
	}

	for msg := range msgs {
		log.Printf("Received a message: %s", msg.Body)
	}
}