function process_message($msg) { $msg_body = json_decode($msg->body, true); if (isset($msg_body['params']) && is_array($msg_body['params'])) { $msg_body['params'] = json_encode($msg_body['params']); } $msg_body = array_values($msg_body); $dispatcher = new ShellDispatcher($msg_body, false); try { $dispatcher->dispatch(); } catch (Exception $e) { RabbitMQ::publish(json_decode($msg->body, true), ['exchange' => 'requeueable', 'queue' => 'requeueable_messages']); $newMessage[] = $msg->body; $newMessage[] = '==>'; $newMessage[] = $e->getMessage(); $newMessage[] = $e->getFile(); $newMessage[] = $e->getLine(); $newMessage[] = $e->getTraceAsString(); $newMessage[] = $e->getCode(); $newMessage[] = $e->getPrevious(); RabbitMQ::publish($newMessage, ['exchange' => 'unprocessed', 'queue' => 'unprocessed_messages']); EmailSender::sendEmail('*****@*****.**', $msg->body, $newMessage); } $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']); // Send a message with the string "quit" to cancel the consumer. if ($msg->body === 'quit') { $msg->delivery_info['channel']->basic_cancel($msg->delivery_info['consumer_tag']); } }
/** * Run the dispatcher * * @param array $argv The argv from PHP * @return void */ public static function run($argv) { $dispatcher = new ShellDispatcher($argv); $dispatcher->_stop($dispatcher->dispatch() === false ? 1 : 0); }
/** * Dispatch a command to another Shell. Similar to Object::requestAction() * but intended for running shells from other shells. * * ### Usage: * * With a string command: * * `return $this->dispatchShell('schema create DbAcl');` * * Avoid using this form if you have string arguments, with spaces in them. * The dispatched will be invoked incorrectly. Only use this form for simple * command dispatching. * * With an array command: * * `return $this->dispatchShell('schema', 'create', 'i18n', '--dry');` * * @return mixed The return of the other shell. * @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::dispatchShell */ public function dispatchShell() { $args = func_get_args(); if (is_string($args[0]) && count($args) === 1) { $args = explode(' ', $args[0]); } $Dispatcher = new ShellDispatcher($args, false); return $Dispatcher->dispatch(); }
/** * Run the dispatcher * * @param array $argv The argv from PHP * * @return void */ public static function run($argv) { $dispatcher = new ShellDispatcher($argv); return $dispatcher->_stop($dispatcher->dispatch() === FALSE ? 1 : 0); }