Repository navigation
Expand file tree
/
Copy pathConsumeMessagesCommand.php
More file actions
65 lines (54 loc) · 1.78 KB
/
Copy pathConsumeMessagesCommand.php
File metadata and controls
65 lines (54 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace Enqueue\Symfony\Consumption;
use Enqueue\Consumption\ChainExtension;
use Enqueue\Consumption\Extension\LoggerExtension;
use Enqueue\Consumption\QueueConsumer;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
class ConsumeMessagesCommand extends Command implements ContainerAwareInterface
{
use ContainerAwareTrait;
use LimitsExtensionsCommandTrait;
/**
* @var QueueConsumer
*/
protected $consumer;
/**
* @param QueueConsumer $consumer
*/
public function __construct(QueueConsumer $consumer)
{
parent::__construct(null);
$this->consumer = $consumer;
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->configureLimitsExtensions();
$this
->setName('enqueue:transport:consume')
->setDescription('A worker that consumes message from a broker. '.
'To use this broker you have to configure queue consumer before adding to the command')
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$extensions = $this->getLimitsExtensions($input, $output);
array_unshift($extensions, new LoggerExtension(new ConsoleLogger($output)));
$runtimeExtensions = new ChainExtension($extensions);
try {
$this->consumer->consume($runtimeExtensions);
} finally {
$this->consumer->getPsrContext()->close();
}
}
}