setName('amqp:remote')
->setDescription('Run a command on an AMQP Consumer')
->setHelp('Run a command on an AMQP Consumer')
->addArgument('name', InputOption::VALUE_REQUIRED, 'Command to execute')
->addOption('args', null, InputOption::VALUE_OPTIONAL|InputOption::VALUE_IS_ARRAY, 'Optional Commands arguments. e.g. --args=key:value --args=key1:value1')
->addOption('route', null, InputOption::VALUE_OPTIONAL, 'AMQP Route Key', '')
;
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('name');
$args = $input->getOption('args');
$date = date("Y-m-d H:i:s");
if ($name) {
$producer = $this->getContainer()->get('old_sound_rabbit_mq.command_producer_producer');
$route = $input->getOption('route');
$producer->publish(serialize(compact('name', 'args')), $route);
$output->writeln("Command executed: {$date} # {$name} # ".implode(" ",$args));
} else {
$output->writeln("Enter a valid command: {$date} # {$name} # ".implode(" ",$args));
}
}
}