From 3148a4afa505f8e58ad915d5816376390b177df5 Mon Sep 17 00:00:00 2001 From: Deepanshu Mehra Date: Mon, 25 Nov 2024 10:44:38 +0530 Subject: [PATCH] feat : listening for events in main.go file --- listener-service/main.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/listener-service/main.go b/listener-service/main.go index d02dc93..091d261 100644 --- a/listener-service/main.go +++ b/listener-service/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "listener/event" "log" "math" "os" @@ -18,7 +19,19 @@ func main() { } defer rabbitConn.Close() - log.Println("Connected to RabbitMQ") + log.Println("Listening for and consuming RabbitMQ messages...") + + // create consumer + consumer, err := event.NewConsumer(rabbitConn) + if err != nil { + panic(err) + } + + // watch the queue and consume events + err = consumer.Listen([]string{"log.INFO", "log.WARNING", "log.ERROR"}) + if err != nil { + log.Println(err) + } } func connect() (*amqp.Connection, error) { @@ -27,7 +40,7 @@ func connect() (*amqp.Connection, error) { var connection *amqp.Connection for { - conn, err := amqp.Dial("amqp://guest:guest@localhost") + conn, err := amqp.Dial("amqp://guest:guest@rabbitmq") if err != nil { fmt.Println("RabbitMQ not yet ready...") counts++