Magento 2 is distinguished by the number of features Magento 1 feels lack. One of the examples is Queues which allow executing time and resource-consuming tasks such as product import, stocks management, API interfaces, indexation asynchronously. Magento 2 box version provides interfaces for accessing AMQP and MySQL queues. As for MySQL, the queues are based on the cron job tasks. This solution performs great for middle-size websites. But there’s an issue concerning high-load projects, as cron job can not manage all scheduled tasks during one iteration. In such a way, the queue can become a potential source of serious bugs.
Our investigations showed that RabbitMQ can be considered as the way out. RabbitMQ service can be connected to Magento 2 by creating a separate module with the queue.xml file, that defines the Queue connection attribute type=”amqp” in it. This workflow gives us access to all Queue functions and allows us to expand default functionality with additional features.
The only real problem you can face while using RabbitMQ is that not every hosting company is eager to install RabbitMQ service by your request. You can setup everything yourself, but it’s not convenient and requires much effort and administrative knowledge.
Let’s suppose Amazon doesn’t provide queues service on RabbitMQ, but it has its own queues service – SQS. The service is simpler than RabbitMQ and doesn’t have additional options. But in most cases, all these extra options are not necessary. As a rule, you need the queue to send messages. SQS has obvious benefit if compared with RabbitMQ. In Amazon ecosystem SQS is available everywhere and doesn’t need to be installed separately. After weighing all the pros and cons, we decided to create a separate module which allows using Amazon SQS service with Magento 2 Queues with ease. You can download the module via packagist.
Now let’s consider how to install the module. In order to connect the module, in the file app/etc/env.php in the section “queues”, you need to enter credentials in the following format:
1 2 3 4 5 6 7 8 9 |
'queue' => array ( 'sqs' => array ( 'region' => '', 'version' => '', 'access_key' => '', 'secret_key' => '', ) |
Then in the file <module_path>/etc/queue.xml you need to update connection type into SQS.
1 2 3 4 5 |
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/queue.xsd"> <broker topic="name.topic" type="sqs" exchange="magento"> <queue consumer="consumerName" name="queue.name"/> </broker> </config> |
Now it’s configured. The rest of it is described in the documents. The only thing you should pay attention to is to specify topology module dependency (belvg/module-sqs) in the setup file when installing the module. Here is the example:
1 2 3 4 5 6 7 8 9 10 11 12 |
/** * UpgradeSchema constructor. * @param Topology $topology */ public function __construct(Belvg\Sqs\Model\Topology $topology) { /** @var TYPE_NAME $topology */ $this->topology = $topology; } … $this->topology->install(); ... |
P.S. The module was tested on Magento 2.1.3-2.1.7 EE. Any bugs can be submitted to the repository https://github.com/Galillei/magento-sqs.
Hi, Denis Yurevich!
Thanks for your comment! You are absolutely right. We will update the article in the nearest time.
Hi Atrsem!
Thank you for the SQS package!
Currently, the /etc/queue.xml is deprecated configuration starting from M2.2:
https://devdocs.magento.com/guides/v2.3/extension-dev-guide/message-queues/queue-migration.html
It will be great if you will update your article.
Also, the Message Queue framework is available in M2.3 CE.
Thank you so much!