x-defaults: &defaults
  restart: unless-stopped
  logging:
    driver: json-file
    options:
      max-size: 100m
      max-file: '3'

services:
  rabbitmq:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}rabbitmq:${RABBITMQ_VERSION:-4.2.3-management-alpine}
    volumes:
      - rabbitmq_data:/var/lib/rabbitmq
    ports:
      - ${RABBITMQ_PORT:-5672}:5672
      - ${RABBITMQ_MANAGEMENT_PORT:-15672}:15672
    environment:
      TZ: ${TZ:-UTC}
      RABBITMQ_DEFAULT_USER: ${RABBITMQ_DEFAULT_USER:-admin}
      RABBITMQ_DEFAULT_PASS: ${RABBITMQ_DEFAULT_PASS:-password}
    deploy:
      resources:
        limits:
          cpus: ${RABBITMQ_CPU_LIMIT:-1.0}
          memory: ${RABBITMQ_MEMORY_LIMIT:-1G}
        reservations:
          cpus: ${RABBITMQ_CPU_RESERVATION:-0.5}
          memory: ${RABBITMQ_MEMORY_RESERVATION:-512M}
    healthcheck:
      test: [CMD, rabbitmq-diagnostics, -q, ping]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

volumes:
  rabbitmq_data:
