Step 32: Using RabbitMQ as a Message Broker

Using RabbitMQ as a Message Broker

To use RabbitMQ instead of PostgreSQL as a message broker:

patch_file

As you might have guessed, we also need to add RabbitMQ to the Docker Compose stack:

patch_file

  1. +++ b/docker-compose.yaml
  2. @@ -21,3 +21,7 @@ services:
  3. redis:
  4. image: redis:5-alpine
  5. ports: [6379]
  6. +
  7. + rabbitmq:
  8. + image: rabbitmq:3.7-management
  9. + ports: [5672, 15672]

To force Docker Compose to take the RabbitMQ container into account, stop the containers and restart them:

Or from the web debug toolbar:

Use guest/guest to login to the RabbitMQ management UI:

Step 32: Using RabbitMQ as a Message Broker - 图2

Adding RabbitMQ to the production servers can be done by adding it to the list of services:

  1. --- a/.symfony/services.yaml
  2. +++ b/.symfony/services.yaml
  3. rediscache:
  4. type: redis:5.0
  5. +
  6. + type: rabbitmq:3.7
  7. + disk: 1024
  8. + size: S

Reference it in the web container configuration as well and enable the amqp PHP extension:

patch_file

When the RabbitMQ service is installed on a project, you can access its web management interface by opening the tunnel first:

  1. $ symfony tunnel:open
  2. $ symfony open:remote:rabbitmq
  3. # when done

Going Further

  • .

This work, including the code samples, is licensed under a Creative Commons BY-NC-SA 4.0 license.