Stratus Magento 2 Guides - Consumer Brokers MySQL to RabbitMQ.

The default broker for consumers in Magento 2.3+ is MySQL, with the exception of the async.operations.all consumer which utilizes RabbitMQ. Please check the Webscale STRATUS Patch Repo for easy-to-install patches to switch brokers for Magento consumers to RabbitMQ.

RabbitMQ vs MySQL

Starting with Magento 2.4.5 Queue Consumers are utilizing RabbitMQ automatically. Any previous versions, when possible, Webscale Stratus recommends using RabbitMQ as the broker instead of MySQL. The Magento Dev docs explain how this can be changed in the env.php file. The RabbitMQ broker provides much better performance than MySQL. We recommend that high traffic sites utilize RabbitMQ for the most often used consumers.

Webscale Patch Repo

Please check the Webscale Patch Repo for easy-to-install patches to switch brokers for Magento consumers to RabbitMQ.

Manual - Single consumer

The following example is for exportProcessor which is a consumer used for exporting data. By default it uses MySQL as a broker.

  1. First confirm that you have RabbitMQ enabled and configured.

  2. Find the XML files for the module in question. For exportprocessor, this the Magento 2 core module named ImportExport located in the app/code/Magento/ImportExport/ directory. Each of these files will have a piece of information that we will need in our configuration.

    • queue_consumer.xml
    • queue_publisher.xml
    • queue_topology.xml

    queue_consumer.xml contains the consumer name Instance names-93

    queue_publisher.xml contains the publisher topic Instance names-93

    queue_topology.xml contains the binding topic Instance names-93

  3. Once you have these pieces of information you can add them to the env.php as follows to switch the RabbitMQ broker for exports:

'queue' => [
        'amqp' => [
            'host' => 'rabbitmq',
            'port' => '5672',
            'user' => 'username',
            'password' => 'yb2sovjbaa4atsbbn0s0ilovemagemojo',
            'virtualhost' => '/',
            'ssl' => 'false',
            'ssl_options' => []
        ],
        'consumers_wait_for_messages' => 1,
        'topics' => [
            'import_export.export' => [
                'publisher' => 'amqp-magento'
            ]
        ],
        'config' => [
            'publishers' => [
                'import_export.export' => [
                    'connections' => [
                        'amqp' => [
                            'name' => 'amqp',
                            'exchange' => 'magento',
                            'disabled' => false
                        ],
                        'db' => [
                            'name' => 'db',
                            'disabled' => true
                        ]
                    ]
                ]
            ]
        ],
        'consumers' => [
            'exportProcessor' => [
                'connection' => 'amqp'
            ]
        ]
    ],

!!! note Afterwards you must run php bin/magento setup:upgrade command so Magento 2 can generate a new queue named “export”. You will see the following output: 2020-11-03 23:05:34.999 [info] <0.8343.0> closing AMQP connection <0.8343.0> (127.0.0.1:38132 -> 127.0.0.1:5672, vhost: ‘/’, user: ‘guest’)

Once setup:upgrade has been run, you can view the new queue that has been created with the rabbitmqadmin command:

rabbitmqadmin --host rabbitmq -u username -p ENTER-PASSWORD-HERE list queues name

Manual - Multiple consumers

This Example is for multiple consumers switched to use RabbitMQ.

'queue' => [
        'amqp' => [
            'host' => 'rabbitmq',
            'port' => '5672',
            'user' => 'username',
            'password' => 'yb2sovjbaa4atsbbn0s0ilovemagemojo',
            'virtualhost' => '/',
            'ssl' => 'false',
            'ssl_options' => []
        ],
        'consumers_wait_for_messages' => 1,
        'topics' => [
            'product_action_attribute.update' => [
                'publisher' => 'amqp-magento'
            ],
            'import_export.export' => [
                'publisher' => 'amqp-magento'
            ]
        ],
        'config' => [
            'publishers' => [
                'product_action_attribute.update' => [
                    'connections' => [
                        'amqp' => [
                            'name' => 'amqp',
                            'exchange' => 'magento',
                            'disabled' => false
                        ],
                        'db' => [
                            'name' => 'db',
                            'disabled' => true
                        ]
                    ]
                ],
                'import_export.export' => [
                    'connections' => [
                        'amqp' => [
                            'name' => 'amqp',
                            'exchange' => 'magento',
                            'disabled' => false
                        ],
                        'db' => [
                            'name' => 'db',
                            'disabled' => true
                        ]
                    ]
                ]
            ]
        ],
        'consumers' => [
            'product_action_attribute.update' => [
                'connection' => 'amqp'
            ],
            'exportProcessor' => [
                'connection' => 'amqp'
            ]
        ]
    ],

Last modified January 1, 0001