The way of setting up magento queues in M2 EE 2.2.* is different from how it used to be in version prior to 2.2.*. The queue.xml
is deprecated and there are 3 new configuration files queue_consumer.xml
, queue_publisher.xml
and queue_topology.xml
.
I've worked on a project to integrate AWS S3 Buckets with Magento. This task uses various cool technologies one of them is RabbitMQ.
So below is an answer which might or might not save some time on setting up message queues in Magento 2.2.*
Best Answer
Pre-requirements
How to get started?
Everything starts from the
communication.xml
file (I assume you're creating a new module), its where you define the topics for the exchanges, topics are used to bind to queues. Here is sample:We now need to tell magento what port and host RabbitMQ is on in
env.php
.Then
queue_topology.xml
, this file is responsible for creating routing rules, queues and exchanges.Then we have the
queue_publisher.xml
, this determines which exchange and connection adapter connection to use for a specific topic.Up to this point once you do a setup:update, you should be able to see
product-import-exchange1
in the exchange list andproductImport-queue
in the list of queues in rabbitMQ, you don't need to manually setup queue or exchanges in rabbitMQ as Magento EE does this for you already.Now we need to create a publisher class, this class will be responsible to publish new message to our queue in rabbitMQ. It would look like something like this
Make sure the data type you are sending matches the data set in
communication.xml
request
attribute. You could do something like this to test if rabbitMQ is receiving any messages.The last thing you need to do is to create a consumer or consumers. You define consumers in
queue_consumer.xml
. Here what it would look like:Now check that the consumer exists
bin/magento queue:consumers:list
, also make sure you build your consumer class, which is defined in the handler attribute of thequeue_consumer.xml
.To start the consumer you use the following:
bin/magento queue:consumers:start CONSUMER_NAME
.References
RabbitMQ Tutorials
Magento 2.2.2 Guide
Magento Migrate 2.1 Queues to 2.2
Getting Started with rabbitMQ and PHP
Also have a look at the modules
module-scalable-checkout
andmodule-scalable-inventory
.