@@ -13,6 +13,7 @@ abstract class BaseConsumerCommand extends BaseRabbitMqCommand
1313{
1414 protected $ consumer ;
1515
16+ /** @var int */
1617 protected $ amount ;
1718
1819 abstract protected function getConsumerService ();
@@ -41,14 +42,22 @@ protected function configure()
4142
4243 $ this
4344 ->addArgument ('name ' , InputArgument::REQUIRED , 'Consumer Name ' )
44- ->addOption ('messages ' , 'm ' , InputOption::VALUE_OPTIONAL , 'Messages to consume ' , 0 )
45+ ->addOption ('messages ' , 'm ' , InputOption::VALUE_OPTIONAL , 'Messages to consume ' , ' 0 ' )
4546 ->addOption ('route ' , 'r ' , InputOption::VALUE_OPTIONAL , 'Routing Key ' , '' )
4647 ->addOption ('memory-limit ' , 'l ' , InputOption::VALUE_OPTIONAL , 'Allowed memory for this process (MB) ' , null )
4748 ->addOption ('debug ' , 'd ' , InputOption::VALUE_NONE , 'Enable Debugging ' )
4849 ->addOption ('without-signals ' , 'w ' , InputOption::VALUE_NONE , 'Disable catching of system signals ' )
4950 ;
5051 }
5152
53+ protected function initialize (InputInterface $ input , OutputInterface $ output )
54+ {
55+ $ this ->amount = (int )$ input ->getOption ('messages ' );
56+ if (0 > $ this ->amount ) {
57+ throw new \InvalidArgumentException ("The -m option should be null or greater than 0 " );
58+ }
59+ }
60+
5261 /**
5362 * Executes the current command.
5463 *
@@ -80,23 +89,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
8089 define ('AMQP_DEBUG ' , (bool ) $ input ->getOption ('debug ' ));
8190 }
8291
83- $ this ->amount = $ input ->getOption ('messages ' );
84-
85- if (0 > (int ) $ this ->amount ) {
86- throw new \InvalidArgumentException ("The -m option should be null or greater than 0 " );
87- }
8892 $ this ->initConsumer ($ input );
8993
9094 return $ this ->consumer ->consume ($ this ->amount );
9195 }
9296
93- protected function initConsumer ($ input )
97+ protected function initConsumer (InputInterface $ input )
9498 {
9599 $ this ->consumer = $ this ->getContainer ()
96100 ->get (sprintf ($ this ->getConsumerService (), $ input ->getArgument ('name ' )));
97101
98- if (!is_null ($ input ->getOption ('memory-limit ' )) && ctype_digit ((string ) $ input ->getOption ('memory-limit ' )) && $ input ->getOption ('memory-limit ' ) > 0 ) {
99- $ this ->consumer ->setMemoryLimit ($ input ->getOption ('memory-limit ' ));
102+ if ($ input ->hasOption ('memory-limit ' )) {
103+ $ memoryLimit = (int )$ input ->getOption ('memory-limit ' );
104+ if ($ memoryLimit > 0 ) {
105+ $ this ->consumer ->setMemoryLimit ($ memoryLimit );
106+ }
100107 }
101108 $ this ->consumer ->setRoutingKey ($ input ->getOption ('route ' ));
102109 }
0 commit comments