|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OldSound\RabbitMqBundle\Command; |
|
4
|
|
|
|
|
5
|
|
|
use OldSound\RabbitMqBundle\RabbitMq\AnonConsumer; |
|
6
|
|
|
use OldSound\RabbitMqBundle\RabbitMq\DynamicConsumer; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
|
|
11
|
|
|
class SetupFabricCommand extends BaseRabbitMqCommand |
|
12
|
|
|
{ |
|
13
|
|
|
protected function configure(): void |
|
14
|
|
|
{ |
|
15
|
|
|
$this |
|
16
|
|
|
->setName('rabbitmq:setup-fabric') |
|
17
|
|
|
->setDescription('Sets up the Rabbit MQ fabric') |
|
18
|
|
|
->addOption('debug', 'd', InputOption::VALUE_NONE, 'Enable Debugging') |
|
19
|
|
|
->addOption('skip-anon-consumers', null, InputOption::VALUE_NONE, 'Do not run the fabric-setup for anonymous consumers') |
|
20
|
|
|
; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
24
|
|
|
{ |
|
25
|
|
|
if (defined('AMQP_DEBUG') === false) { |
|
26
|
|
|
define('AMQP_DEBUG', (bool) $input->getOption('debug')); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$skipAnonConsumers = (bool) $input->getOption('skip-anon-consumers'); |
|
30
|
|
|
|
|
31
|
|
|
$output->writeln('Setting up the Rabbit MQ fabric'); |
|
32
|
|
|
|
|
33
|
|
|
if ($skipAnonConsumers && $output->isVeryVerbose()) { |
|
34
|
|
|
$output->writeln('Skipping fabric-setup for anonymous consumers'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
$partsHolder = $this->getContainer()->get('old_sound_rabbit_mq.parts_holder'); |
|
38
|
|
|
|
|
39
|
|
|
foreach (['base_amqp', 'binding'] as $key) { |
|
40
|
|
|
foreach ($partsHolder->getParts('old_sound_rabbit_mq.' . $key) as $baseAmqp) { |
|
41
|
|
|
if ( |
|
42
|
|
|
$baseAmqp instanceof DynamicConsumer |
|
43
|
|
|
|| ($skipAnonConsumers && $baseAmqp instanceof AnonConsumer) |
|
44
|
|
|
) { |
|
45
|
|
|
continue; |
|
46
|
|
|
} |
|
47
|
|
|
$baseAmqp->setupFabric(); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return 0; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|