-
Notifications
You must be signed in to change notification settings - Fork 0
/
push_notif.go
59 lines (46 loc) · 1.13 KB
/
push_notif.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
57
58
59
package main
import (
"log"
"mailer/token"
"mailer/rabbitmq"
"mailer/notification"
"mailer/interfaces"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Println("Error loading .env file:", err)
}
queueName := "notification_queue"
conn, err := rabbitmq.ConnectToRabbitMQ()
if err != nil {
log.Fatal(err)
}
defer conn.Close()
ch, err := conn.Channel()
if err != nil {
log.Fatal(err)
}
defer ch.Close()
err = rabbitmq.DeclareQueue(ch, queueName)
if err != nil {
log.Fatal(err)
}
messages, err := rabbitmq.ConsumeMessages(ch, queueName)
if err != nil {
log.Fatal(err)
}
log.Printf("[*] Waiting for messages.")
var recordInterfaces interfaces.Notification
for msg := range messages {
log.Printf("Received message: %s", msg.Body)
record := token.DecodeToken(string(msg.Body), &recordInterfaces)
if record != nil {
log.Println(record)
}else{
log.Println("Data => ",recordInterfaces)
notification.SendNotification(recordInterfaces, record)
}
}
}