AMQPRemoteCommand.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace WorkflowBundle\Command;
  3. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  4. use Symfony\Component\Console\Input\InputInterface;
  5. use Symfony\Component\Console\Input\InputOption;
  6. use Symfony\Component\Console\Output\OutputInterface;
  7. class AMQPRemoteCommand extends ContainerAwareCommand
  8. {
  9. protected function configure()
  10. {
  11. $this
  12. ->setName('amqp:remote')
  13. ->setDescription('Run a command on an AMQP Consumer')
  14. ->setHelp('Run a command on an AMQP Consumer')
  15. ->addArgument('name', InputOption::VALUE_REQUIRED, 'Command to execute')
  16. ->addOption('args', null, InputOption::VALUE_OPTIONAL|InputOption::VALUE_IS_ARRAY, 'Optional Commands arguments. e.g. --args=key:value --args=key1:value1')
  17. ->addOption('route', null, InputOption::VALUE_OPTIONAL, 'AMQP Route Key', '')
  18. ;
  19. }
  20. /**
  21. * @param InputInterface $input
  22. * @param OutputInterface $output
  23. */
  24. protected function execute(InputInterface $input, OutputInterface $output)
  25. {
  26. $name = $input->getArgument('name');
  27. $args = $input->getOption('args');
  28. if ($name) {
  29. $msg = array(
  30. 'name' => $name,
  31. 'args' => $args,
  32. );
  33. $producer = $this->getContainer()->get('old_sound_rabbit_mq.command_producer_producer');
  34. $route = $input->getOption('route');
  35. $producer->publish(serialize(compact('name', 'args')), $route);
  36. $output->writeln('<info>Command executed!</info>');
  37. } else {
  38. $output->writeln('<error>Enter a valid command</error>');
  39. }
  40. }
  41. }