How should I structure dockerized RabbitMQ?

Viewed 1843

I am trying to migrate our monolithic PHP Symfony app to a somewhat more scalable solution with Docker. There is some communication between the app and RabbitMQ, and I use docker-compose to bring all the containers up, in this case the app and the RabbitMQ server.

There is a lot of discussions around the topic that one container should spawn only one process, and the Docker best practices is somewhat vague regarding this point:

While this mantra has good intentions, it is not necessarily true that there should be only one operating system process per container. In addition to the fact that containers can now be spawned with an init process, some programs might spawn additional processes of their own accord.

Does it make sense to create a separate Docker container for each RabbitMQ consumer? It kind of feels "right" and "clean" to not let rabbitmq server know of language/tools used to process the queue. I came up with (relevant parts of docker-compose.yml):

  app :
    # my php-fpm app container

  rabbitmq_server:
    container_name: sf.rabbitmq_server
    build: .docker/rabbitmq
    ports:
        - "15672:15672"
        - "5672:5672"
    networks:
      - app_network

  rabbitmq_consumer:
    container_name: sf.rabbit_consumer
    extends: app
    depends_on:
      - rabbitmq_server
    working_dir: /app
    command: "php bin/console rabbitmq:consumer test"
    networks:
      - app_network

I could run several consumers in the rabbitmq_consumer container using nohup or some other way of running them in the background.

I guess my questions are:

Can I somehow automate the "adding a new consumer", so that I would not have to edit the "build script" of Docker (and others, like ansible) every time the new consumer is added from the code?

Does it make sense to separate RabbitMQ server from Consumers, or should I use the Rabbit server with consumers running in the background?

Or should they be placed in the background of the app container?

1 Answers
Related