8 use Symfony\Component\Console\Command\Command;
9 use Symfony\Component\Console\Input\InputArgument;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Input\InputOption;
12 use Symfony\Component\Console\Output\OutputInterface;
31 private $consumerFactory;
41 private $pidConsumerManager;
58 $this->appState = $appState;
59 $this->consumerFactory = $consumerFactory;
61 ->get(PidConsumerManager::class);
62 parent::__construct(
$name);
70 $consumerName = $input->getArgument(self::ARGUMENT_CONSUMER);
71 $numberOfMessages = $input->getOption(self::OPTION_NUMBER_OF_MESSAGES);
72 $batchSize = (int)$input->getOption(self::OPTION_BATCH_SIZE);
73 $areaCode = $input->getOption(self::OPTION_AREACODE);
74 $pidFilePath = $input->getOption(self::PID_FILE_PATH);
76 if ($pidFilePath && $this->pidConsumerManager->isRun($pidFilePath)) {
77 $output->writeln(
'<error>Consumer with the same PID is running</error>');
78 return \Magento\Framework\Console\Cli::RETURN_FAILURE;
82 $this->pidConsumerManager->savePid($pidFilePath);
85 if ($areaCode !==
null) {
86 $this->appState->setAreaCode($areaCode);
88 $this->appState->setAreaCode(
'global');
91 $consumer = $this->consumerFactory->get($consumerName, $batchSize);
92 $consumer->process($numberOfMessages);
93 return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
101 $this->setName(self::COMMAND_QUEUE_CONSUMERS_START);
102 $this->setDescription(
'Start MessageQueue consumer');
104 self::ARGUMENT_CONSUMER,
105 InputArgument::REQUIRED,
106 'The name of the consumer to be started.' 109 self::OPTION_NUMBER_OF_MESSAGES,
111 InputOption::VALUE_REQUIRED,
112 'The number of messages to be processed by the consumer before process termination. ' 113 .
'If not specified - terminate after processing all queued messages.' 116 self::OPTION_BATCH_SIZE,
118 InputOption::VALUE_REQUIRED,
119 'The number of messages per batch. Applicable for the batch consumer only.' 122 self::OPTION_AREACODE,
124 InputOption::VALUE_REQUIRED,
125 'The preferred area (global, adminhtml, etc...) ' 126 .
'default is global.' 131 InputOption::VALUE_REQUIRED,
132 'The file path for saving PID' 136 This command starts MessageQueue consumer by its
name.
138 To start consumer which will process all queued messages and terminate execution:
140 <comment>%command.full_name% someConsumer</comment>
142 To specify the number of messages which should be processed by consumer before its termination:
144 <comment>%command.full_name% someConsumer --max-messages=50</comment>
146 To specify the number of messages per batch
for the batch consumer:
148 <comment>%command.full_name% someConsumer --batch-size=500</comment>
150 To specify the preferred area:
152 <comment>%command.full_name% someConsumer --area-code=
'adminhtml'</comment>
154 To save PID enter path:
156 <comment>%command.full_name% someConsumer --pid-file-path=
'/var/someConsumer.pid'</comment>
__construct(\Magento\Framework\App\State $appState, ConsumerFactory $consumerFactory, $name=null, PidConsumerManager $pidConsumerManager=null)
execute(InputInterface $input, OutputInterface $output)
const COMMAND_QUEUE_CONSUMERS_START
const OPTION_NUMBER_OF_MESSAGES
if(!isset($_GET['name'])) $name