layout | parent | title | nav_order |
---|---|---|---|
default |
Magento |
Quick tour |
1 |
{% include support.md %}
The module integrates Enqueue Client with Magento1. You can send and consume messages to different message queues such as RabbitMQ, AMQP, STOMP, Amazon SQS, Kafka, Redis, Google PubSub, Gearman, Beanstalk, Google PubSub and others. Or integrate Magento2 app with other applications or service via Message Bus. There is a module for Magento2 too.
We use composer and cotya/magento-composer-installer plugin to install magento-enqueue extension.
To install libraries run the commands in the application root directory.
composer require "magento-hackathon/magento-composer-installer:~3.0"
composer require "enqueue/magento-enqueue:*@dev" "enqueue/amqp-ext"
Note: You could use not only AMQP transport but any other available.
At this stage we have configure the Enqueue extension in Magento backend.
The config is here: System -> Configuration -> Enqueue Message Queue
.
Here's the example of Amqp transport that connects to RabbitMQ broker on localhost:
To send a message you have to take enqueue helper and call send
method.
<?php
Mage::helper('enqueue')->send('a_topic', 'aMessage');
I assume you have acme
Magento module properly created, configured and registered.
To consume messages you have to define a processor class first:
<?php
// app/code/local/Acme/Module/Helper/Async/Foo.php
use Interop\Queue\Context;
use Interop\Queue\Message;
use Interop\Queue\Processor;
class Acme_Module_Helper_Async_Foo implements Processor
{
public function process(Message $message, Context $context)
{
// do job
// $message->getBody() -> 'payload'
return self::ACK; // acknowledge message
// return self::REJECT; // reject message
// return self::REQUEUE; // requeue message
}
}
than subscribe it to a topic or several topics:
<!-- app/etc/local.xml -->
<config>
<default>
<enqueue>
<processors>
<foo-processor>
<topic>a_topic</topic>
<helper>acme/async_foo</helper>
</foo-processor>
</processors>
</enqueue>
</default>
</config>
and run message consume command:
$ php shell/enqueue.php enqueue:consume -vvv --setup-broker