serviceContainer = $serviceContainer; } /** * $msg will be an instance of `PhpAmqpLib\Message\AMQPMessage` * with the $msg->body being the data sent over RabbitMQ. * * @param AMQPMessage $msg */ public function execute(AMQPMessage $msg) { $msgBody = unserialize($msg->getBody()); if (isset($msgBody['name']) && isset($msgBody['args'])) { // command name and args $name = $msgBody['name']; $args = $msgBody['args']; $kernel = $this->serviceContainer->get('kernel'); $application = new Application($kernel); $application->setAutoExit(false); $input = array('command' => $name,); foreach ($args as $arg) { $pos = strpos($arg, ':'); if ($pos) { $input[substr($arg, 0, $pos)] = substr($arg, $pos + 1); } } $input = new ArrayInput($input); $output = new BufferedOutput(); $application->run($input, $output); // return the output $content = $output->fetch(); echo $content; return true; } return false; } }