diff --git a/README.md b/README.md index 43cad61dc..0a915c762 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/docs/images/magento2_enqueue_configuration.png b/docs/images/magento2_enqueue_configuration.png new file mode 100644 index 000000000..475b461d5 Binary files /dev/null and b/docs/images/magento2_enqueue_configuration.png differ diff --git a/docs/index.md b/docs/index.md index 15045f7c7..ad34cae9c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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) diff --git a/docs/magento/cli_commands.md b/docs/magento/cli_commands.md index e6681b90a..e963b4e62 100644 --- a/docs/magento/cli_commands.md +++ b/docs/magento/cli_commands.md @@ -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. @@ -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 diff --git a/docs/magento/quick_tour.md b/docs/magento/quick_tour.md index c2232ce6b..f2b32d0b3 100644 --- a/docs/magento/quick_tour.md +++ b/docs/magento/quick_tour.md @@ -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. diff --git a/docs/magento2/cli_commands.md b/docs/magento2/cli_commands.md new file mode 100644 index 000000000..b25939098 --- /dev/null +++ b/docs/magento2/cli_commands.md @@ -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] [--] []... + 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 + 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) + diff --git a/docs/magento2/quick_tour.md b/docs/magento2/quick_tour.md new file mode 100644 index 000000000..f5d85b5a2 --- /dev/null +++ b/docs/magento2/quick_tour.md @@ -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 +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 +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 + + + + + + + + a_topic + acme/async_foo + + + + + +``` + +and run message consume command: + +```bash +$ php bin/magento enqueue:consume -vvv --setup-broker +``` + +[back to index](../index.md#magento2) \ No newline at end of file