|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OldSound\RabbitMqBundle\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
9
|
|
|
|
|
10
|
|
|
class RpcServerCommand extends BaseRabbitMqCommand |
|
11
|
|
|
{ |
|
12
|
|
|
protected function configure() |
|
13
|
|
|
{ |
|
14
|
|
|
parent::configure(); |
|
15
|
|
|
|
|
16
|
|
|
$this |
|
17
|
|
|
->setName('rabbitmq:rpc-server') |
|
18
|
|
|
->setDescription('Start an RPC server') |
|
19
|
|
|
->addArgument('name', InputArgument::REQUIRED, 'Server Name') |
|
20
|
|
|
->addOption('messages', 'm', InputOption::VALUE_OPTIONAL, 'Messages to consume', 0) |
|
21
|
|
|
->addOption('debug', 'd', InputOption::VALUE_OPTIONAL, 'Debug mode', false) |
|
22
|
|
|
; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Executes the current command. |
|
27
|
|
|
* |
|
28
|
|
|
* @param InputInterface $input An InputInterface instance |
|
29
|
|
|
* @param OutputInterface $output An OutputInterface instance |
|
30
|
|
|
* |
|
31
|
|
|
* @return integer 0 if everything went fine, or an error code |
|
32
|
|
|
* |
|
33
|
|
|
* @throws \InvalidArgumentException When the number of messages to consume is less than 0 |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
36
|
|
|
{ |
|
37
|
|
|
define('AMQP_DEBUG', (bool) $input->getOption('debug')); |
|
38
|
|
|
$amount = $input->getOption('messages'); |
|
39
|
|
|
|
|
40
|
|
|
if (0 > (int) $amount) { |
|
41
|
|
|
throw new \InvalidArgumentException("The -m option should be null or greater than 0"); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$this->getContainer() |
|
45
|
|
|
->get(sprintf('old_sound_rabbit_mq.%s_server', $input->getArgument('name'))) |
|
|
|
|
|
|
46
|
|
|
->start($amount); |
|
47
|
|
|
|
|
48
|
|
|
return 0; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|