-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[doc][magento2][skip ci] Add docs for Mangeto2 module.
- Loading branch information
Showing
7 changed files
with
265 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
# Magento2. Cli commands | ||
|
||
The enqueue Magento extension provides several commands. | ||
The most useful one `enqueue:consume` connects to the broker and process the messages. | ||
Other commands could be useful during debugging (like `enqueue:topics`) or deployment (like `enqueue:setup-broker`). | ||
|
||
* [enqueue:consume](#enqueueconsume) | ||
* [enqueue:produce](#enqueueproduce) | ||
* [enqueue:setup-broker](#enqueuesetup-broker) | ||
* [enqueue:queues](#enqueuequeues) | ||
* [enqueue:topics](#enqueuetopics) | ||
|
||
## enqueue:consume | ||
|
||
``` | ||
php bin/magento enqueue:consume --help | ||
Usage: | ||
enqueue:consume [options] [--] [<client-queue-names>]... | ||
enq:c | ||
Arguments: | ||
client-queue-names Queues to consume messages from | ||
Options: | ||
--message-limit=MESSAGE-LIMIT Consume n messages and exit | ||
--time-limit=TIME-LIMIT Consume messages during this time | ||
--memory-limit=MEMORY-LIMIT Consume messages until process reaches this memory limit in MB | ||
--setup-broker Creates queues, topics, exchanges, binding etc on broker side. | ||
--idle-timeout=IDLE-TIMEOUT The time in milliseconds queue consumer idle if no message has been received. | ||
--receive-timeout=RECEIVE-TIMEOUT The time in milliseconds queue consumer waits for a message. | ||
--skip[=SKIP] Queues to skip consumption of messages from (multiple values allowed) | ||
-h, --help Display this help message | ||
-q, --quiet Do not output any message | ||
-V, --version Display this application version | ||
--ansi Force ANSI output | ||
--no-ansi Disable ANSI output | ||
-n, --no-interaction Do not ask any interactive question | ||
-e, --env=ENV The environment name [default: "test"] | ||
--no-debug Switches off debug mode | ||
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug | ||
Help: | ||
A client's worker that processes messages. By default it connects to default queue. It select an appropriate message processor based on a message headers | ||
``` | ||
|
||
## enqueue:produce | ||
|
||
``` | ||
php bin/magento enqueue:produce --help | ||
Usage: | ||
enqueue:produce <topic> <message> | ||
enq:p | ||
Arguments: | ||
topic A topic to send message to | ||
message A message to send | ||
Options: | ||
-h, --help Display this help message | ||
-q, --quiet Do not output any message | ||
-V, --version Display this application version | ||
--ansi Force ANSI output | ||
--no-ansi Disable ANSI output | ||
-n, --no-interaction Do not ask any interactive question | ||
-e, --env=ENV The environment name [default: "dev"] | ||
--no-debug Switches off debug mode | ||
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug | ||
Help: | ||
A command to send a message to topic | ||
``` | ||
|
||
## enqueue:setup-broker | ||
|
||
``` | ||
php bin/magento enqueue:setup-broker --help | ||
Usage: | ||
enqueue:setup-broker | ||
enq:sb | ||
Options: | ||
-h, --help Display this help message | ||
-q, --quiet Do not output any message | ||
-V, --version Display this application version | ||
--ansi Force ANSI output | ||
--no-ansi Disable ANSI output | ||
-n, --no-interaction Do not ask any interactive question | ||
-e, --env=ENV The environment name [default: "dev"] | ||
--no-debug Switches off debug mode | ||
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug | ||
Help: | ||
Creates all required queues | ||
``` | ||
|
||
## enqueue:queues | ||
|
||
``` | ||
php bin/magento enqueue:queues --help | ||
Usage: | ||
enqueue:queues | ||
enq:m:q | ||
debug:enqueue:queues | ||
Options: | ||
-h, --help Display this help message | ||
-q, --quiet Do not output any message | ||
-V, --version Display this application version | ||
--ansi Force ANSI output | ||
--no-ansi Disable ANSI output | ||
-n, --no-interaction Do not ask any interactive question | ||
-e, --env=ENV The environment name [default: "dev"] | ||
--no-debug Switches off debug mode | ||
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug | ||
Help: | ||
A command shows all available queues and some information about them. | ||
``` | ||
|
||
## enqueue:topics | ||
|
||
``` | ||
php bin/magento enqueue:topics --help | ||
Usage: | ||
enqueue:topics | ||
enq:m:t | ||
debug:enqueue:topics | ||
Options: | ||
-h, --help Display this help message | ||
-q, --quiet Do not output any message | ||
-V, --version Display this application version | ||
--ansi Force ANSI output | ||
--no-ansi Disable ANSI output | ||
-n, --no-interaction Do not ask any interactive question | ||
-e, --env=ENV The environment name [default: "dev"] | ||
--no-debug Switches off debug mode | ||
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug | ||
Help: | ||
A command shows all available topics and some information about them. | ||
``` | ||
|
||
[back to index](../index.md#magento2) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Magento2 EnqueueModule | ||
|
||
The module integrates [Enqueue Client](../client/quick_tour.md) with Magento2. 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](../client/message_bus.md). | ||
There is [a module](../magento/quick_tour.md) for Magento1 too. | ||
|
||
## Installation | ||
|
||
We recommend using [composer](https://getcomposer.org/) to install [magento2-enqueue](https://github.com/php-enqueue/magento-enqueue) module. To install libraries run the commands in the application root directory. | ||
|
||
```bash | ||
composer require "enqueue/magento2-enqueue:*@dev" "enqueue/amqp-ext" | ||
``` | ||
|
||
Run setup:upgrade so Magento2 picks up the installed module. | ||
|
||
```bash | ||
php bin/magento setup:upgrade | ||
``` | ||
|
||
## Configuration | ||
|
||
At this stage we have configure the Enqueue extension in Magento backend. | ||
The config is here: `Stores -> Configuration -> General -> Enqueue Message Queue`. | ||
Here's the example of Amqp transport that connects to RabbitMQ broker on localhost: | ||
|
||
![Сonfiguration](../images/magento2_enqueue_configuration.png) | ||
|
||
## Publish Message | ||
|
||
To send a message you have to take enqueue helper and call `send` method. | ||
|
||
```php | ||
<?php | ||
|
||
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); | ||
$enqueueManager = $objectManager->create('Enqueue\Enqueue\Model\EnqueueManager'); | ||
$enqueueManager->send('a_topic', 'aMessage'); | ||
``` | ||
|
||
## Message Consumption | ||
|
||
I assume you have `acme` Magento module properly created, configured and registered. | ||
To consume messages you have to define a processor class first: | ||
|
||
```php | ||
<?php | ||
// app/code/Acme/Module/Helper/Async/Foo.php | ||
|
||
namespace Acme\Module\Helper\Async; | ||
|
||
use Interop\Queue\PsrContext; | ||
use Interop\Queue\PsrMessage; | ||
use Interop\Queue\PsrProcessor; | ||
|
||
class Foo implements PsrProcessor | ||
{ | ||
public function process(PsrMessage $message, PsrContext $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: | ||
|
||
|
||
```xml | ||
<!-- 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: | ||
|
||
```bash | ||
$ php bin/magento enqueue:consume -vvv --setup-broker | ||
``` | ||
|
||
[back to index](../index.md#magento2) |