Skip to content

Commit f64ba28

Browse files
committed
bind processors
1 parent df156ae commit f64ba28

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

shell/enqueue.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@
2020
// init
2121
Mage::app('admin', 'store');
2222

23-
/** @var \Enqueue\Client\SimpleClient $client */
24-
$client = Mage::helper('enqueue')->getClient();
23+
/** @var \Enqueue_Enqueue_Helper_Data $enqueue */
24+
$enqueue = Mage::helper('enqueue');
25+
$enqueue->bindProcessors();
2526

26-
//bind message processor
27-
//$helper = Mage::helper('helper-name');
28-
//$client->bind('topic', 'consumer-name', [$helper, 'method-name']);
27+
/** @var \Enqueue\Client\SimpleClient $client */
28+
$client = $enqueue->getClient();
2929

3030
$application = new Application();
31-
3231
$application->add(new SetupBrokerCommand($client->getDriver()));
3332
$application->add(new ProduceMessageCommand($client->getProducer()));
3433
$application->add(new QueuesCommand($client->getQueueMetaRegistry()));

src/Enqueue/Enqueue/Helper/Data.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,41 @@
11
<?php
22

3+
use Enqueue\Psr\PsrProcessor;
4+
35
class Enqueue_Enqueue_Helper_Data extends Mage_Core_Helper_Data
46
{
57
/**
68
* @var \Enqueue\Client\SimpleClient
79
*/
810
private $client;
911

12+
public function bindProcessors()
13+
{
14+
if (false == $processors = Mage::getStoreConfig('enqueue/processors')) {
15+
return;
16+
}
17+
18+
foreach ($processors as $name => $config) {
19+
if (empty($config['topic'])) {
20+
throw new \LogicException('Topic name is not set for processor: "%s"', $name);
21+
}
22+
23+
if (empty($config['helper'])) {
24+
throw new \LogicException('Helper name is not set for processor: "%s"', $name);
25+
}
26+
27+
$this->getClient()->bind($config['topic'], $name, function () use ($config) {
28+
$processor = Mage::helper($config['helper']);
29+
30+
if (false == $processor instanceof PsrProcessor) {
31+
throw new \LogicException();
32+
}
33+
34+
call_user_func_array([$processor, 'process'], func_get_args());
35+
});
36+
}
37+
}
38+
1039
public function getClient()
1140
{
1241
if (null === $this->client) {

0 commit comments

Comments
 (0)