Set up RabbitMQ service
The Message Queue Framework (MQF) is a system within Magento Commerce that allows a module to publish messages to queues. It also defines the consumers that will receive the messages asynchronously.
The MQF uses RabbitMQ as the messaging broker, which provides a scalable platform for sending and receiving messages. It also includes a mechanism for storing undelivered messages. RabbitMQ is based on the Advanced Message Queuing Protocol (AMQP) 0.9.1 specification.
We support RabbitMQ version 3.5.
If you prefer using an existing AMQP-based service, like RabbitMQ, instead of relying on Magento Commerce (Cloud) to create it for you, use the QUEUE_CONFIGURATION
environment variable to connect it to your site.
Add RabbitMQ in services.yaml and .magento.app.yaml
To enable RabbitMQ, add the following code with your installed version and allocated disk space in MB to the .magento/services.yaml
file.
To configure the relationships for the environment variable, set a relationship in your .magento.app.yaml
in the Git branch. For example:
Merge and deploy the code to set the configurations for RabbitMQ. For information on how these changes affect your environments, see services.yaml
.
Verify environment-related relationships
We use the Magento Commerce (Cloud) environment variable $MAGENTO_CLOUD_RELATIONSHIPS
, a JSON object, to retrieve environment-related relationships.
To verify this information used for configurations and settings:
- SSH into the Integration environment with RabbitMQ installed and configured.
-
Enter the following command to pretty-print connection information for RabbitMQ:
php -r 'print_r(json_decode(base64_decode($_ENV["MAGENTO_CLOUD_RELATIONSHIPS"])));'
The response includes all relationships for services and configuration data for that environment. In the response, you will locate data similar to the following for RabbitMQ:
Connect to RabbitMQ for debugging
For debugging purposes, it’s sometimes useful to directly connect to a service instance in one of the following ways:
- Connect from your local development environment
- Connect from the application
- Connect from your PHP application
Connect from your local development environment
You can do this using SSH tunneling:
- SSH into the Integration environment with RabbitMQ installed and configured.
-
Login to the Magento Cloud CLI and project:
magento-cloud login
- Use
magento-cloud tunnel:open
to open a tunnel to the app. For information on this command, add--help
. -
Use the following command to pretty-print your relationships. This lets you see which username and password to use, and you can verify the remote service’s port.
php -r 'print_r(json_decode(base64_decode($_ENV["MAGENTO_CLOUD_RELATIONSHIPS"])));'
-
Use the
ssh -L
command to enable local port forwarding to RabbitMQ as follows:ssh -L <port number>:mq.internal:<port number> <project ID>-<branch ID>@ssh.us.magentosite.cloud
- While the session is open, you can start a RabbitMQ client of your choice from your local workstation, configured to connect to the
localhost:<portnumber
using the user name and password you found in the relationship variable. For this example, you would uselocalhost:5672
.
Connect from the application
To connect to RabbitMQ running in an application, you should install a client like amqp-utils as a project dependency in your .magento.app.yaml
file.
For example,
Then, when you SSH into your PHP container, you enter any amqp-
command available to manage your queues.
Connect from your PHP application
To connect to RabbitMQ using your PHP application, add a PHP library (like PHP AMQPlib) to your source tree.