update makefile and docker file for listener

This commit is contained in:
2024-09-06 18:54:35 +02:00
parent fc8e500c5b
commit e05aa83ff5
4 changed files with 37 additions and 3 deletions

View File

@ -0,0 +1,8 @@
FROM alpine:latest
RUN mkdir /app
COPY listenerApp /app
CMD ["/app/listenerApp"]

View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"listener/event"
"log"
"math"
"os"
@ -21,10 +22,19 @@ func main() {
log.Println("Connected to RabbitMQ")
// start listening for messages
log.Println("Listening for and consuming RabbitMQ messages...")
// create consumer
consumer, err := event.NewConsumer(rabbitConn)
if err != nil {
log.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) {
@ -33,7 +43,7 @@ func connect() (*amqp.Connection, error) {
// don't continue until rabbit is ready
for {
c, err := amqp.Dial("amqp://guest:guest@localhost") // XXX: credentials
c, err := amqp.Dial("amqp://guest:guest@rabbitmq") // XXX: credentials
if err != nil {
fmt.Println("RabbitMQ not yet ready...")
counts++