update makefile and docker file for listener
This commit is contained in:
		
							
								
								
									
										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 (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
 | 
						"listener/event"
 | 
				
			||||||
	"log"
 | 
						"log"
 | 
				
			||||||
	"math"
 | 
						"math"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
@ -21,10 +22,19 @@ func main() {
 | 
				
			|||||||
	log.Println("Connected to RabbitMQ")
 | 
						log.Println("Connected to RabbitMQ")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// start listening for messages
 | 
						// start listening for messages
 | 
				
			||||||
 | 
						log.Println("Listening for and consuming RabbitMQ messages...")
 | 
				
			||||||
	// create consumer
 | 
						// create consumer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						consumer, err := event.NewConsumer(rabbitConn)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Panic(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// watch the queue and consume events
 | 
						// 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) {
 | 
					func connect() (*amqp.Connection, error) {
 | 
				
			||||||
@ -33,7 +43,7 @@ func connect() (*amqp.Connection, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// don't continue until rabbit is ready
 | 
						// don't continue until rabbit is ready
 | 
				
			||||||
	for {
 | 
						for {
 | 
				
			||||||
		c, err := amqp.Dial("amqp://guest:guest@localhost") // XXX: credentials
 | 
							c, err := amqp.Dial("amqp://guest:guest@rabbitmq") // XXX: credentials
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			fmt.Println("RabbitMQ not yet ready...")
 | 
								fmt.Println("RabbitMQ not yet ready...")
 | 
				
			||||||
			counts++
 | 
								counts++
 | 
				
			||||||
 | 
				
			|||||||
@ -3,6 +3,7 @@ BROKER_BINARY=brokerApp
 | 
				
			|||||||
AUTH_BINARY=authApp
 | 
					AUTH_BINARY=authApp
 | 
				
			||||||
LOGGER_BINARY=loggerApp
 | 
					LOGGER_BINARY=loggerApp
 | 
				
			||||||
MAIL_BINARY=mailApp
 | 
					MAIL_BINARY=mailApp
 | 
				
			||||||
 | 
					LISTENER_BINARY=listenerApp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## up: starts all containers in the background without forcing build
 | 
					## up: starts all containers in the background without forcing build
 | 
				
			||||||
up:
 | 
					up:
 | 
				
			||||||
@ -11,7 +12,7 @@ up:
 | 
				
			|||||||
	@echo "Docker images started!"
 | 
						@echo "Docker images started!"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## up_build: stops docker-compose (if running), builds all projects and starts docker compose
 | 
					## 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...)"
 | 
						@echo "Stopping docker images (if running...)"
 | 
				
			||||||
	docker compose down
 | 
						docker compose down
 | 
				
			||||||
	@echo "Building (when required) and starting docker images..."
 | 
						@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
 | 
						cd ../mail-service && env GOOS=linux CGO_ENABLED=0 go build -o ${MAIL_BINARY} ./cmd/api
 | 
				
			||||||
	@echo "Done!"
 | 
						@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: builds the frone end binary
 | 
				
			||||||
build_front:
 | 
					build_front:
 | 
				
			||||||
	@echo "Building front end binary..."
 | 
						@echo "Building front end binary..."
 | 
				
			||||||
 | 
				
			|||||||
@ -50,6 +50,15 @@ services:
 | 
				
			|||||||
      FROM_ADDR: me@here.com
 | 
					      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:
 | 
					  postgres:
 | 
				
			||||||
    image: postgres:16.4-alpine
 | 
					    image: postgres:16.4-alpine
 | 
				
			||||||
    ports:
 | 
					    ports:
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user