Skip to content

Commit 9eef61e

Browse files
authored
Merge pull request #401 from php-enqueue/doc-magento2
[doc][magento2][skip ci] Add docs for Mangeto2 module.
2 parents c89d8ef + af9381c commit 9eef61e

File tree

7 files changed

+272
-15
lines changed

7 files changed

+272
-15
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Features:
6767
[![Latest Stable Version](https://poser.pugx.org/enqueue/null/version.png)](https://packagist.org/packages/enqueue/null)
6868
* [Symfony bundle](docs/bundle/quick_tour.md)
6969
* [Magento1 extension](docs/magento/quick_tour.md)
70+
* [Magento2 module](docs/magento2/quick_tour.md)
7071
* [Laravel extension](docs/laravel/quick_tour.md)
7172
* [Yii2. Amqp driver](docs/yii/amqp_driver.md)
7273
* [Message bus](docs/quick_tour.md#client) support.
199 KB
Loading

docs/index.md

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
* [Magento](#magento)
4545
- [Quick tour](magento/quick_tour.md)
4646
- [Cli commands](magento/cli_commands.md)
47+
* [Magento2](#magento2)
48+
- [Quick tour](magento2/quick_tour.md)
49+
- [Cli commands](magento2/cli_commands.md)
4750
* [Yii](#yii)
4851
- [AMQP Interop driver](yii/amqp_driver.md)
4952
* [EnqueueElasticaBundle. Overview](elastica-bundle/overview.md)

docs/magento/cli_commands.md

+18-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Cli commands
1+
# Magento. Cli commands
22

33
The enqueue Magento extension provides several commands.
44
The most useful one `enqueue:consume` connects to the broker and process the messages.
@@ -19,22 +19,25 @@ Usage:
1919
enq:c
2020
2121
Arguments:
22-
client-queue-names Queues to consume messages from
22+
client-queue-names Queues to consume messages from
2323
2424
Options:
25-
--message-limit=MESSAGE-LIMIT Consume n messages and exit
26-
--time-limit=TIME-LIMIT Consume messages during this time
27-
--memory-limit=MEMORY-LIMIT Consume messages until process reaches this memory limit in MB
28-
--setup-broker Creates queues, topics, exchanges, binding etc on broker side.
29-
-h, --help Display this help message
30-
-q, --quiet Do not output any message
31-
-V, --version Display this application version
32-
--ansi Force ANSI output
33-
--no-ansi Disable ANSI output
34-
-n, --no-interaction Do not ask any interactive question
35-
-e, --env=ENV The environment name [default: "dev"]
36-
--no-debug Switches off debug mode
37-
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
25+
--message-limit=MESSAGE-LIMIT Consume n messages and exit
26+
--time-limit=TIME-LIMIT Consume messages during this time
27+
--memory-limit=MEMORY-LIMIT Consume messages until process reaches this memory limit in MB
28+
--setup-broker Creates queues, topics, exchanges, binding etc on broker side.
29+
--idle-timeout=IDLE-TIMEOUT The time in milliseconds queue consumer idle if no message has been received.
30+
--receive-timeout=RECEIVE-TIMEOUT The time in milliseconds queue consumer waits for a message.
31+
--skip[=SKIP] Queues to skip consumption of messages from (multiple values allowed)
32+
-h, --help Display this help message
33+
-q, --quiet Do not output any message
34+
-V, --version Display this application version
35+
--ansi Force ANSI output
36+
--no-ansi Disable ANSI output
37+
-n, --no-interaction Do not ask any interactive question
38+
-e, --env=ENV The environment name [default: "test"]
39+
--no-debug Switches off debug mode
40+
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
3841
3942
Help:
4043
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

docs/magento/quick_tour.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Magento Enqueue. Quick tour
22

3+
The module integrates [Enqueue Client](../client/quick_tour.md) 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](../client/message_bus.md).
4+
There is [a module](../magento2/quick_tour.md) for Magento2 too.
5+
36
## Installation
47

58
We use [composer](https://getcomposer.org/) and [cotya/magento-composer-installer](https://github.com/Cotya/magento-composer-installer) plugin to install [magento-enqueue](https://github.com/php-enqueue/magento-enqueue) extension.
@@ -11,6 +14,8 @@ composer require "magento-hackathon/magento-composer-installer:~3.0"
1114
composer require "enqueue/magento-enqueue:*@dev" "enqueue/amqp-ext"
1215
```
1316

17+
_**Note**: You could use not only AMQP transport but any other [available](../transport)._
18+
1419
## Configuration
1520

1621
At this stage we have configure the Enqueue extension in Magento backend.

docs/magento2/cli_commands.md

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Magento2. Cli commands
2+
3+
The enqueue Magento extension provides several commands.
4+
The most useful one `enqueue:consume` connects to the broker and process the messages.
5+
Other commands could be useful during debugging (like `enqueue:topics`) or deployment (like `enqueue:setup-broker`).
6+
7+
* [enqueue:consume](#enqueueconsume)
8+
* [enqueue:produce](#enqueueproduce)
9+
* [enqueue:setup-broker](#enqueuesetup-broker)
10+
* [enqueue:queues](#enqueuequeues)
11+
* [enqueue:topics](#enqueuetopics)
12+
13+
## enqueue:consume
14+
15+
```
16+
php bin/magento enqueue:consume --help
17+
Usage:
18+
enqueue:consume [options] [--] [<client-queue-names>]...
19+
enq:c
20+
21+
Arguments:
22+
client-queue-names Queues to consume messages from
23+
24+
Options:
25+
--message-limit=MESSAGE-LIMIT Consume n messages and exit
26+
--time-limit=TIME-LIMIT Consume messages during this time
27+
--memory-limit=MEMORY-LIMIT Consume messages until process reaches this memory limit in MB
28+
--setup-broker Creates queues, topics, exchanges, binding etc on broker side.
29+
--idle-timeout=IDLE-TIMEOUT The time in milliseconds queue consumer idle if no message has been received.
30+
--receive-timeout=RECEIVE-TIMEOUT The time in milliseconds queue consumer waits for a message.
31+
--skip[=SKIP] Queues to skip consumption of messages from (multiple values allowed)
32+
-h, --help Display this help message
33+
-q, --quiet Do not output any message
34+
-V, --version Display this application version
35+
--ansi Force ANSI output
36+
--no-ansi Disable ANSI output
37+
-n, --no-interaction Do not ask any interactive question
38+
-e, --env=ENV The environment name [default: "test"]
39+
--no-debug Switches off debug mode
40+
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
41+
42+
Help:
43+
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
44+
```
45+
46+
## enqueue:produce
47+
48+
```
49+
php bin/magento enqueue:produce --help
50+
Usage:
51+
enqueue:produce <topic> <message>
52+
enq:p
53+
54+
Arguments:
55+
topic A topic to send message to
56+
message A message to send
57+
58+
Options:
59+
-h, --help Display this help message
60+
-q, --quiet Do not output any message
61+
-V, --version Display this application version
62+
--ansi Force ANSI output
63+
--no-ansi Disable ANSI output
64+
-n, --no-interaction Do not ask any interactive question
65+
-e, --env=ENV The environment name [default: "dev"]
66+
--no-debug Switches off debug mode
67+
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
68+
69+
Help:
70+
A command to send a message to topic
71+
```
72+
73+
## enqueue:setup-broker
74+
75+
```
76+
php bin/magento enqueue:setup-broker --help
77+
Usage:
78+
enqueue:setup-broker
79+
enq:sb
80+
81+
Options:
82+
-h, --help Display this help message
83+
-q, --quiet Do not output any message
84+
-V, --version Display this application version
85+
--ansi Force ANSI output
86+
--no-ansi Disable ANSI output
87+
-n, --no-interaction Do not ask any interactive question
88+
-e, --env=ENV The environment name [default: "dev"]
89+
--no-debug Switches off debug mode
90+
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
91+
92+
Help:
93+
Creates all required queues
94+
```
95+
96+
## enqueue:queues
97+
98+
```
99+
php bin/magento enqueue:queues --help
100+
Usage:
101+
enqueue:queues
102+
enq:m:q
103+
debug:enqueue:queues
104+
105+
Options:
106+
-h, --help Display this help message
107+
-q, --quiet Do not output any message
108+
-V, --version Display this application version
109+
--ansi Force ANSI output
110+
--no-ansi Disable ANSI output
111+
-n, --no-interaction Do not ask any interactive question
112+
-e, --env=ENV The environment name [default: "dev"]
113+
--no-debug Switches off debug mode
114+
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
115+
116+
Help:
117+
A command shows all available queues and some information about them.
118+
```
119+
120+
## enqueue:topics
121+
122+
```
123+
php bin/magento enqueue:topics --help
124+
Usage:
125+
enqueue:topics
126+
enq:m:t
127+
debug:enqueue:topics
128+
129+
Options:
130+
-h, --help Display this help message
131+
-q, --quiet Do not output any message
132+
-V, --version Display this application version
133+
--ansi Force ANSI output
134+
--no-ansi Disable ANSI output
135+
-n, --no-interaction Do not ask any interactive question
136+
-e, --env=ENV The environment name [default: "dev"]
137+
--no-debug Switches off debug mode
138+
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
139+
140+
Help:
141+
A command shows all available topics and some information about them.
142+
```
143+
144+
[back to index](../index.md#magento2)
145+

docs/magento2/quick_tour.md

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Magento2 EnqueueModule
2+
3+
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).
4+
There is [a module](../magento/quick_tour.md) for Magento1 too.
5+
6+
## Installation
7+
8+
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.
9+
10+
```bash
11+
composer require "enqueue/magento2-enqueue:*@dev" "enqueue/amqp-ext"
12+
```
13+
14+
Run setup:upgrade so Magento2 picks up the installed module.
15+
16+
```bash
17+
php bin/magento setup:upgrade
18+
```
19+
20+
## Configuration
21+
22+
At this stage we have configure the Enqueue extension in Magento backend.
23+
The config is here: `Stores -> Configuration -> General -> Enqueue Message Queue`.
24+
Here's the example of Amqp transport that connects to RabbitMQ broker on localhost:
25+
26+
![Сonfiguration](../images/magento2_enqueue_configuration.png)
27+
28+
## Publish Message
29+
30+
To send a message you have to take enqueue helper and call `send` method.
31+
32+
```php
33+
<?php
34+
35+
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
36+
$enqueueManager = $objectManager->create('Enqueue\Enqueue\Model\EnqueueManager');
37+
$enqueueManager->sendEvent('a_topic', 'aMessage');
38+
39+
// or a command with a possible reply
40+
$reply = $enqueueManager->sendCommand('a_topic', 'aMessage', true);
41+
42+
$replyMessage = $reply->receive(5000); // wait for 5 sec
43+
```
44+
45+
## Message Consumption
46+
47+
I assume you have `acme` Magento module properly created, configured and registered.
48+
To consume messages you have to define a processor class first:
49+
50+
```php
51+
<?php
52+
// app/code/Acme/Module/Helper/Async/Foo.php
53+
54+
namespace Acme\Module\Helper\Async;
55+
56+
use Interop\Queue\PsrContext;
57+
use Interop\Queue\PsrMessage;
58+
use Interop\Queue\PsrProcessor;
59+
60+
class Foo implements PsrProcessor
61+
{
62+
public function process(PsrMessage $message, PsrContext $context)
63+
{
64+
// do job
65+
// $message->getBody() -> 'payload'
66+
67+
return self::ACK; // acknowledge message
68+
// return self::REJECT; // reject message
69+
// return self::REQUEUE; // requeue message
70+
}
71+
}
72+
```
73+
74+
than subscribe it to a topic or several topics:
75+
76+
77+
```xml
78+
<!-- app/etc/local.xml -->
79+
80+
<config>
81+
<default>
82+
<enqueue>
83+
<processors>
84+
<foo-processor>
85+
<topic>a_topic</topic>
86+
<helper>acme/async_foo</helper>
87+
</foo-processor>
88+
</processors>
89+
</enqueue>
90+
</default>
91+
</config>
92+
```
93+
94+
and run message consume command:
95+
96+
```bash
97+
$ php bin/magento enqueue:consume -vvv --setup-broker
98+
```
99+
100+
[back to index](../index.md#magento2)

0 commit comments

Comments
 (0)