/** * Send message to AMQP server. * * @param SyncTask $task */ protected function send($task) { $channel = $this->connection->channel(); if ($channel) { $channel->exchange_declare($task->getExchange(), $task->getPublishingType(), false, true, false); $content = json_encode(['id' => $task->getId(), 'task' => 'ongr.acme_task.' . $task->getName(), 'args' => [implode(' ', array_merge([$task->getCommand(), '-e', $this->getEnvironment($task)], $task->getArguments()))]]); $message = new AMQPMessage($content, ['content_type' => 'application/json']); $this->logger && $this->logger->info('amqp publish', [$task->getName(), $task->getPublishingType(), $task->getHost()]); $channel->basic_publish($message, $task->getExchange(), $task->getHost()); $channel->close(); } }
/** * Method to test getCommand and getExchange methods with live-search case. */ public function testExchangeCommandLiveSearch() { $name = 'live_search'; $expectedExchange = 'live_search'; $task = new SyncTask(SyncTask::SYNC_TASK_BROADCAST); $task->setName($name); $this->assertEquals($expectedExchange, $task->getExchange()); $this->setExpectedException('InvalidArgumentException'); $task->getCommand(); }