ConsumerListCommand.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\MessageQueue\Console;
  7. use Symfony\Component\Console\Command\Command;
  8. use Magento\Framework\MessageQueue\ConfigInterface as QueueConfig;
  9. use Symfony\Component\Console\Input\InputInterface;
  10. use Symfony\Component\Console\Output\OutputInterface;
  11. use Magento\Framework\MessageQueue\Consumer\ConfigInterface as ConsumerConfig;
  12. /**
  13. * Command for starting MessageQueue consumers.
  14. */
  15. class ConsumerListCommand extends Command
  16. {
  17. const COMMAND_QUEUE_CONSUMERS_LIST = 'queue:consumers:list';
  18. /**
  19. * @var ConsumerConfig
  20. */
  21. private $consumerConfig;
  22. /**
  23. * Initialize dependencies.
  24. *
  25. * @param QueueConfig $queueConfig
  26. * @param string|null $name
  27. *
  28. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  29. */
  30. public function __construct(QueueConfig $queueConfig, $name = null)
  31. {
  32. parent::__construct($name);
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. protected function execute(InputInterface $input, OutputInterface $output)
  38. {
  39. $consumers = $this->getConsumers();
  40. $output->writeln($consumers);
  41. return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. protected function configure()
  47. {
  48. $this->setName(self::COMMAND_QUEUE_CONSUMERS_LIST);
  49. $this->setDescription('List of MessageQueue consumers');
  50. $this->setHelp(
  51. <<<HELP
  52. This command shows list of MessageQueue consumers.
  53. HELP
  54. );
  55. parent::configure();
  56. }
  57. /**
  58. * @return string[]
  59. */
  60. private function getConsumers()
  61. {
  62. $consumerNames = [];
  63. foreach ($this->getConsumerConfig()->getConsumers() as $consumer) {
  64. $consumerNames[] = $consumer->getName();
  65. }
  66. return $consumerNames;
  67. }
  68. /**
  69. * Get consumer config.
  70. *
  71. * @return ConsumerConfig
  72. *
  73. * @deprecated 100.2.0
  74. */
  75. private function getConsumerConfig()
  76. {
  77. if ($this->consumerConfig === null) {
  78. $this->consumerConfig = \Magento\Framework\App\ObjectManager::getInstance()->get(ConsumerConfig::class);
  79. }
  80. return $this->consumerConfig;
  81. }
  82. }