# https://docs.docker.com/compose/compose-file/
version: "3.6"

# https://docs.docker.com/compose/compose-file/#networks
networks:
  rabbitmq-prometheus:

# https://docs.docker.com/compose/compose-file/#volumes
volumes:
  rabbitmq-prometheus_prometheus:
  rabbitmq-prometheus_grafana:

services:
  rmq0-qq: &rabbitmq
    # https://hub.docker.com/r/pivotalrabbitmq/rabbitmq/tags
    image: pivotalrabbitmq/rabbitmq:master-otp-max
    networks:
      - "rabbitmq-prometheus"
    ports:
      - "15679:15672"
      - "15699:15692"
    # https://unix.stackexchange.com/questions/71940/killing-tcp-connection-in-linux
    # https://en.wikipedia.org/wiki/Tcpkill
    # https://www.digitalocean.com/community/tutorials/iptables-essentials-common-firewall-rules-and-commands#block-an-ip-address
    cap_add:
      - ALL
    hostname: rmq0-qq
    environment:
      RABBITMQ_ERLANG_COOKIE: rabbitmq-prometheus
      # Uncomment the following line if you want debug logs & colour
      # RABBITMQ_LOG: debug,+color
    volumes:
      # This does not work that well on Windows
      # https://github.com/rabbitmq/rabbitmq-prometheus/commit/c4b04ea9bae877ff7d22a7085475965016933d91#commitcomment-40660523
      # - ./erlang.cookie:/var/lib/rabbitmq/.erlang.cookie
      - ./rabbitmq-qq.conf:/etc/rabbitmq/rabbitmq.conf:ro
      - ./rabbitmq-qq-env.conf:/etc/rabbitmq/rabbitmq-env.conf:ro
      - ./rabbitmq-qq-definitions.json:/etc/rabbitmq/rabbitmq-definitions.json:ro
  rmq1-qq:
    << : *rabbitmq
    hostname: rmq1-qq
    ports:
      - "15680:15672"
      - "15700:15692"
  rmq2-qq:
    << : *rabbitmq
    hostname: rmq2-qq
    ports:
      - "15681:15672"
      - "15701:15692"
  qq-moderate-load:
    image: &perf-test-image pivotalrabbitmq/perf-test:2.15.0-ubuntu
    networks:
      - "rabbitmq-prometheus"
    environment:
      URIS: "amqp://guest:guest@rmq0-qq:5672/%2f,amqp://guest:guest@rmq1-qq:5672/%2f,amqp://guest:guest@rmq2-qq:5672/%2f"
      CONFIRM: 50
      QUEUE_PATTERN: "qq%d"
      QUEUE_PATTERN_FROM: 1
      QUEUE_PATTERN_TO: 10
      PRODUCERS: 10
      CONSUMERS: 10
      QUEUE_ARGS: x-queue-type=quorum,x-max-length=1000
      FLAG: persistent
      AUTO_DELETE: "false"
      RATE: 50
      AUTOACK: "false"
      SERVERS_STARTUP_TIMEOUT: &startup_timeout 30
      METRICS_PROMETHEUS: "true"
