Skip to content

Commit

Permalink
feat : listening for events in main.go file
Browse files Browse the repository at this point in the history
  • Loading branch information
dmehra2102 committed Nov 25, 2024
1 parent 33fa97d commit 3148a4a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions listener-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"listener/event"
"log"
"math"
"os"
Expand All @@ -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) {
Expand All @@ -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++
Expand Down

0 comments on commit 3148a4a

Please sign in to comment.