update makefile and docker file for listener
This commit is contained in:
parent
fc8e500c5b
commit
e05aa83ff5
8
listener-service/listener-service.dockerfile
Normal file
8
listener-service/listener-service.dockerfile
Normal file
@ -0,0 +1,8 @@
|
||||
FROM alpine:latest
|
||||
|
||||
RUN mkdir /app
|
||||
|
||||
COPY listenerApp /app
|
||||
|
||||
CMD ["/app/listenerApp"]
|
||||
|
@ -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++
|
||||
|
@ -3,6 +3,7 @@ BROKER_BINARY=brokerApp
|
||||
AUTH_BINARY=authApp
|
||||
LOGGER_BINARY=loggerApp
|
||||
MAIL_BINARY=mailApp
|
||||
LISTENER_BINARY=listenerApp
|
||||
|
||||
## up: starts all containers in the background without forcing build
|
||||
up:
|
||||
@ -11,7 +12,7 @@ up:
|
||||
@echo "Docker images started!"
|
||||
|
||||
## up_build: stops docker-compose (if running), builds all projects and starts docker compose
|
||||
up_build: build_broker build_auth build_logger build_mail
|
||||
up_build: build_broker build_auth build_logger build_mail build_listener
|
||||
@echo "Stopping docker images (if running...)"
|
||||
docker compose down
|
||||
@echo "Building (when required) and starting docker images..."
|
||||
@ -48,6 +49,12 @@ build_mail:
|
||||
cd ../mail-service && env GOOS=linux CGO_ENABLED=0 go build -o ${MAIL_BINARY} ./cmd/api
|
||||
@echo "Done!"
|
||||
|
||||
## build_listener: builds the listener binary as a linux executable
|
||||
build_listener:
|
||||
@echo "Building listener binary..."
|
||||
cd ../listener-service && env GOOS=linux CGO_ENABLED=0 go build -o ${LISTENER_BINARY} .
|
||||
@echo "Done!"
|
||||
|
||||
## build_front: builds the frone end binary
|
||||
build_front:
|
||||
@echo "Building front end binary..."
|
||||
|
@ -50,6 +50,15 @@ services:
|
||||
FROM_ADDR: me@here.com
|
||||
|
||||
|
||||
listener-service:
|
||||
build:
|
||||
context: ./../listener-service/
|
||||
dockerfile: ./../listener-service/listener-service.dockerfile
|
||||
restart: always
|
||||
deploy:
|
||||
mode: replicated
|
||||
replicas: 1
|
||||
|
||||
postgres:
|
||||
image: postgres:16.4-alpine
|
||||
ports:
|
||||
|
Loading…
Reference in New Issue
Block a user