Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc][magento2][skip ci] Add docs for Mangeto2 module. #401

Merged
merged 2 commits into from
Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Features:
[![Latest Stable Version](https://poser.pugx.org/enqueue/null/version.png)](https://packagist.org/packages/enqueue/null)
* [Symfony bundle](docs/bundle/quick_tour.md)
* [Magento1 extension](docs/magento/quick_tour.md)
* [Magento2 module](docs/magento2/quick_tour.md)
* [Laravel extension](docs/laravel/quick_tour.md)
* [Yii2. Amqp driver](docs/yii/amqp_driver.md)
* [Message bus](docs/quick_tour.md#client) support.
Expand Down
Binary file added docs/images/magento2_enqueue_configuration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
* [Magento](#magento)
- [Quick tour](magento/quick_tour.md)
- [Cli commands](magento/cli_commands.md)
* [Magento2](#magento2)
- [Quick tour](magento2/quick_tour.md)
- [Cli commands](magento2/cli_commands.md)
* [Yii](#yii)
- [AMQP Interop driver](yii/amqp_driver.md)
* [EnqueueElasticaBundle. Overview](elastica-bundle/overview.md)
Expand Down
33 changes: 18 additions & 15 deletions docs/magento/cli_commands.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Cli commands
# Magento. Cli commands

The enqueue Magento extension provides several commands.
The most useful one `enqueue:consume` connects to the broker and process the messages.
Expand All @@ -19,22 +19,25 @@ Usage:
enq:c

Arguments:
client-queue-names Queues to consume messages from
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.
-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
--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
Expand Down
5 changes: 5 additions & 0 deletions docs/magento/quick_tour.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Magento Enqueue. Quick tour

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).
There is [a module](../magento2/quick_tour.md) for Magento2 too.

## Installation

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.
Expand All @@ -11,6 +14,8 @@ 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](../transport)._

## Configuration

At this stage we have configure the Enqueue extension in Magento backend.
Expand Down
145 changes: 145 additions & 0 deletions docs/magento2/cli_commands.md
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)

100 changes: 100 additions & 0 deletions docs/magento2/quick_tour.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# 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->sendEvent('a_topic', 'aMessage');

// or a command with a possible reply
$reply = $enqueueManager->sendCommand('a_topic', 'aMessage', true);

$replyMessage = $reply->receive(5000); // wait for 5 sec
```

## 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)