0

I'm trying to communicate my microservices using rabbitmq(a docker container of that service). So every time I run my app it deliver

[Nest] 18  - 04/12/2025, 12:58:29 PM     LOG [NestFactory] Starting Nest application...
[Nest] 18  - 04/12/2025, 12:58:29 PM     LOG [InstanceLoader] AppModule dependencies initialized +5ms
[Nest] 18  - 04/12/2025, 12:58:29 PM     LOG [InstanceLoader] ClientsModule dependencies initialized +0ms
[Nest] 18  - 04/12/2025, 12:58:29 PM   ERROR [Server] Connection to transport failed. Trying to reconnect...
[Nest] 18  - 04/12/2025, 12:58:29 PM   ERROR [Server] AggregateError [ECONNREFUSED]: 
    at internalConnectMultiple (node:net:1139:18)
    at afterConnectMultiple (node:net:1712:7) {
  code: 'ECONNREFUSED',
  [errors]: [
    Error: connect ECONNREFUSED ::1:5672
        at createConnectionError (node:net:1675:14)
        at afterConnectMultiple (node:net:1705:16) {
      errno: -111,
      code: 'ECONNREFUSED',
      syscall: 'connect',
      address: '::1',
      port: 5672
    },
    Error: connect ECONNREFUSED 127.0.0.1:5672
        at createConnectionError (node:net:1675:14)
        at afterConnectMultiple (node:net:1705:16) {
      errno: -111,
      code: 'ECONNREFUSED',
      syscall: 'connect',
      address: '127.0.0.1',
      port: 5672
    }
  ]
}

My .env:

PORT=3001

RABBITMQ_URL=amqp://localhost:15672
RABBITMQ_QUEUE=properties_queue
RABBITMQ_USER=guest
RABBITMQ_PASSWORD=guest
RABBITMQ_QUEUE_DURABLE=false

My docker-compose.yml:

  version: '3.8'

services:
  properties-ms:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: properties-ms
    ports:
      - "${PORT}:${PORT}" # Mapea el puerto definido en el .env
    environment:
      - PORT=${PORT}
      - RABBITMQ_URL=${RABBITMQ_URL}
      - RABBITMQ_QUEUE=${RABBITMQ_QUEUE}
      - RABBITMQ_USER=${RABBITMQ_USER}
      - RABBITMQ_PASSWORD=${RABBITMQ_PASSWORD}
      - RABBITMQ_QUEUE_DURABLE=${RABBITMQ_QUEUE_DURABLE}
    networks:
      - servers_default # Cambia a la red correcta

networks:
  servers_default: # Define la red como externa
    external: true

Have somebody idea what kind of error may be causing this? I run the app using Makefile:

COMPOSE_FILE = docker-compose.yml

build:
    @echo "Building the properties-ms container..."
    docker compose -f $(COMPOSE_FILE) build

run:
    @echo "Running the properties-ms container..."
    docker compose -f $(COMPOSE_FILE) up -d properties-ms

clean: stop
    @echo "Cleaning volumes, containers, and networks..."
    docker compose -f $(COMPOSE_FILE) down -v --rmi all

stop:
    @echo "Stopping the properties-ms container..."
    docker compose -f $(COMPOSE_FILE) down

restart: stop run

logs:
    @echo "Showing logs for the properties-ms container..."
    docker logs -f properties-ms

status:
    @echo "Checking container status..."
    docker ps

Dockerfile:

# Usa una imagen base estable de Node.js
FROM node:lts-alpine

# Establece el directorio de trabajo dentro del contenedor
WORKDIR /app

# Copia los archivos necesarios para instalar dependencias
COPY package*.json ./
COPY tsconfig*.json ./

# Instala todas las dependencias (producción y desarrollo)
RUN npm ci

# Copia el resto de los archivos del proyecto
COPY . .

# Compila el proyecto TypeScript
RUN npm run build

# Elimina las dependencias de desarrollo para reducir el tamaño de la imagen
RUN npm prune --production

# Expone el puerto del gateway
EXPOSE 3000

# Comando para iniciar la aplicación
CMD ["npm", "run", "start:prod"]
3
  • 2
    Your environment variables are for your app but you don't show how you run your app. It also looks like you want it to connect on port 15672 but the error messages say that you're trying to connect on port 5672. Please edit your post and show how you run your app. And make sure your env file and error messages are from the same run of the app. Commented Apr 12 at 13:35
  • 15672 is for the UI, not the AMQP Port Commented Apr 15 at 17:45
  • The error says it cannot connect to the RabbitMQ service, which means the connection string is invalid. RABBITMQ_URL=amqp://localhost:15672; here replace localhost with the proper hostname (the service name in the docker-compose file), also, use the port of 5672; you've specified the dashboard port. Additionally, check that the port is published (exposed) and is available. Furthermore, check that the ENV variable is properly read and passed to the RabbitMQ client to initialize. Commented Apr 16 at 10:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.