Durable queues do not survive container stop

68 Views Asked by At

I have the following setup:

version: '3.8'

services:
  rabbitmq:
      image: rabbitmq:3-management
      container_name: 'rabbitmq'
      volumes:
            - ./rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf
            - rabbitmq_data:/var/lib/rabbitmq/mnesia/'
      environment:
          - RABBITMQ_DEFAULT_USER=guest
          - RABBITMQ_DEFAULT_PASS=guest
          - RABBITMQ_CONFIG_FILE=/etc/rabbitmq/rabbitmq.conf
      ports:
          - 5672:5672
          - 15672:15672
      networks:
        - test-network

networks:
    test-network:
        driver: bridge

volumes:
  rabbitmq_data: {}

And I have the following pika code:

import pika
import sys


if __name__ == '__main__':
    connection = pika.BlockingConnection(
        pika.ConnectionParameters(host='localhost'))
    channel = connection.channel()

    channel.exchange_declare(exchange='E1', durable=True)
    channel.queue_declare(queue='Q1', durable=True)
    channel.queue_bind(queue='Q1', exchange='E1', routing_key='q1')
    message = b' '.join(sys.argv[1:]) or b"info: Hello World!"
    channel.basic_publish(
        exchange='E1',
        routing_key='q1',
        body=message
    )
    print(f" [x] Sent {message}")
    connection.close()

I expect that after running docker compose down, if I run the container again, the queue will still be alive along with the unacknowledged message. But when I open the web interface, the exchange and queue are both gone away:

enter image description here

1

There are 1 best solutions below

1
Luke Bakken On

- rabbitmq_data:/var/lib/rabbitmq/mnesia

should be

- rabbitmq_data:/var/lib/rabbitmq