Skip to content

Commit 0cffd0b

Browse files
committed
Update readme. change namespace. add sendCommand method. do not use deprecated send method.
1 parent fd337d3 commit 0cffd0b

File tree

11 files changed

+39
-105
lines changed

11 files changed

+39
-105
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor
2+
composer.lock

Console/CommandList.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Enqueue\Enqueue\Console;
6+
namespace Enqueue\Magento2\Console;
77

88
use Enqueue\Symfony\Client\ConsumeMessagesCommand;
99
use Enqueue\Symfony\Client\Meta\QueuesCommand;
@@ -40,22 +40,22 @@ class CommandList implements \Magento\Framework\Console\CommandListInterface
4040
*/
4141
private $queuesCommandFactory;
4242
/**
43-
* @var \Enqueue\Enqueue\Model\EnqueueManager
43+
* @var \Enqueue\Magento2\Model\EnqueueManager
4444
*/
4545
private $enqueueManager;
4646

4747
/**
4848
* CommandList constructor.
4949
*
50-
* @param \Enqueue\Enqueue\Model\EnqueueManager $enqueueManager
50+
* @param \Enqueue\Magento2\Model\EnqueueManager $enqueueManager
5151
* @param \Enqueue\Symfony\Client\SetupBrokerCommandFactory $setupBrokerCommandFactory
5252
* @param \Enqueue\Symfony\Client\Meta\QueuesCommandFactory $queuesCommandFactory
5353
* @param \Enqueue\Symfony\Client\Meta\TopicsCommandFactory $topicsCommandFactory
5454
* @param \Enqueue\Symfony\Client\ProduceMessageCommandFactory $produceMessageCommandFactory
5555
* @param \Enqueue\Symfony\Client\ConsumeMessagesCommandFactory $consumeMessagesCommand
5656
*/
5757
public function __construct(
58-
\Enqueue\Enqueue\Model\EnqueueManager $enqueueManager,
58+
\Enqueue\Magento2\Model\EnqueueManager $enqueueManager,
5959
\Enqueue\Symfony\Client\SetupBrokerCommandFactory $setupBrokerCommandFactory,
6060
\Enqueue\Symfony\Client\Meta\QueuesCommandFactory $queuesCommandFactory,
6161
\Enqueue\Symfony\Client\Meta\TopicsCommandFactory $topicsCommandFactory,

Model/Config/Source/Redis/Vendor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Enqueue\Enqueue\Model\Config\Source\Redis;
3+
namespace Enqueue\Magento2\Model\Config\Source\Redis;
44

55
class Vendor
66
{

Model/Config/Source/Transport.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Enqueue\Enqueue\Model\Config\Source;
3+
namespace Enqueue\Magento2\Model\Config\Source;
44

55
class Transport
66
{

Model/EnqueueManager.php

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22

3-
namespace Enqueue\Enqueue\Model;
3+
namespace Enqueue\Magento2\Model;
44

55
use Enqueue\Client\Message;
6+
use Enqueue\Rpc\Promise;
67
use Enqueue\SimpleClient\SimpleClient;
78
use Interop\Queue\PsrProcessor;
89

@@ -66,14 +67,25 @@ public function bindProcessors()
6667
}
6768
}
6869

69-
7070
/**
7171
* @param string $topic
7272
* @param string|array|Message $message
7373
*/
74-
public function send($topic, $message)
74+
public function sendEvent($topic, $message)
75+
{
76+
$this->getProducer()->sendEvent($topic, $message);
77+
}
78+
79+
/**
80+
* @param string $command
81+
* @param string|array|Message $message
82+
* @param bool $needReply
83+
*
84+
* @return Promise|null the promise is returned if needReply argument is true
85+
*/
86+
public function sendCommand($command, $message, $needReply = false)
7587
{
76-
$this->getProducer()->send($topic, $message);
88+
return $this->getProducer()->sendCommand($command, $message, $needReply);
7789
}
7890

7991
/**

Plugin/Model/Config/ConfigPlugin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Enqueue\Enqueue\Plugin\Model\Config;
3+
namespace Enqueue\Magento2\Plugin\Model\Config;
44

55
use \Enqueue\AmqpExt\AmqpContext;
66
use \Enqueue\Stomp\StompContext;

README.md

+10-90
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,17 @@
11
# Magento2 EnqueueModule
22

3+
[![Gitter](https://badges.gitter.im/php-enqueue/Lobby.svg)](https://gitter.im/php-enqueue/Lobby)
4+
[![Total Downloads](https://poser.pugx.org/enqueue/magento2-enqueue/d/total.png)](https://packagist.org/packages/enqueue/magento2-enqueue)
5+
[![Latest Stable Version](https://poser.pugx.org/enqueue/magento2-enqueue/version.png)](https://packagist.org/packages/enqueue/magento2-enqueue)
6+
37
The module integrates [Enqueue Client](https://github.com/php-enqueue/enqueue-dev/blob/master/docs/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](https://github.com/php-enqueue/enqueue-dev/blob/master/docs/client/message_bus.md).
48

5-
## Installation
9+
## Resources
610

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

9616
## Developed by Forma-Pro
9717

@@ -103,4 +23,4 @@ If you have any questions and inquires about our open source development, this p
10323

10424
## License
10525

106-
It is released under the [MIT License](LICENSE).
26+
It is released under the [MIT License](LICENSE).

cli_commands.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
* See COPYING.txt for license details.
55
*/
66
if (PHP_SAPI == 'cli') {
7-
\Magento\Framework\Console\CommandLocator::register(\Enqueue\Enqueue\Console\CommandList::class);
7+
\Magento\Framework\Console\CommandLocator::register(\Enqueue\Magento2\Console\CommandList::class);
88
}

enqueue_doc.png

-199 KB
Binary file not shown.

etc/adminhtml/system.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<label>Transport</label>
1212
<field id="default" translate="label comment" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
1313
<label>Default</label>
14-
<source_model>Enqueue\Enqueue\Model\Config\Source\Transport</source_model>
14+
<source_model>Enqueue\Magento2\Model\Config\Source\Transport</source_model>
1515
</field>
1616
</group>
1717
<group id="client" translate="label" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
@@ -198,7 +198,7 @@
198198
</field>
199199
<field id="vendor" translate="label comment" type="select" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0">
200200
<label>Vendor</label>
201-
<source_model>Enqueue\Enqueue\Model\Config\Source\Redis\Vendor</source_model>
201+
<source_model>Enqueue\Magento2\Model\Config\Source\Redis\Vendor</source_model>
202202
</field>
203203
<field id="lazy" translate="label comment" type="select" sortOrder="40" showInDefault="1" showInWebsite="0" showInStore="0">
204204
<label>Lazy Connection</label>

etc/di.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
-->
77
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
88
<type name="\Magento\Config\Model\Config">
9-
<plugin name="config_data_plugin" type="Enqueue\Enqueue\Plugin\Model\Config\ConfigPlugin"/>
9+
<plugin name="config_data_plugin" type="Enqueue\Magento2\Plugin\Model\Config\ConfigPlugin"/>
1010
</type>
1111
</config>

0 commit comments

Comments
 (0)