Esempio n. 1
0
 /**
  * @test
  * @expectedException \PhpAmqpLib\Exception\AMQPProtocolChannelException
  */
 public function deleteNonExistentBindingThrowsException()
 {
     try {
         $this->admin->declareQueue(new Tx_Amqp_Messaging_Queue(self::TEST_QUEUE, FALSE, FALSE, TRUE));
         $this->admin->deleteBinding(new Tx_Amqp_Messaging_Binding(self::TEST_QUEUE, Tx_Amqp_Messaging_Binding::DESTINATION_QUEUE, uniqid() . '_non_existent_exchange', uniqid() . '_non_existent_routing'));
     } catch (Exception $e) {
         $admin = $this->createAdminService();
         $admin->deleteQueue(self::TEST_QUEUE);
         throw $e;
     }
 }
 /**
  * Tests the basic.return if a message cannot be delivered immediately.
  *
  * @test
  */
 public function routeToQueueWithNoListenersShouldBasicReturn()
 {
     $this->markTestSkipped('immediate=true has been removed since RabbitMQ 3.0.0');
     $queue = $this->admin->declareQueue();
     $this->service->setImmediate(TRUE);
     $self = $this;
     $messageBody = 'basic.return with no consumers listening';
     $this->service->send(new \PhpAmqpLib\Message\AMQPMessage($messageBody), Tx_Amqp_Messaging_AMQPService::DEFAULT_EXCHANGE, $queue->getName());
     $this->service->handleReturn(function (Tx_Amqp_Messaging_UndeliverableMessage $message) use($self, $messageBody) {
         $self->assertEquals($messageBody, $message->getMessage()->body);
         Tx_Amqp_Messaging_AMQPUtils::throwStopException();
     });
     $this->admin->deleteQueue($queue->getName());
 }
 protected function getConnectionStatus()
 {
     try {
         $service = new Tx_Amqp_Messaging_AMQPService(Tx_Amqp_Util_ConfigurationHelper::getConnectionFactory());
         $admin = new Tx_Amqp_Messaging_AMQPAdmin($service);
         $queue = $admin->declareQueue();
         $messageBody = 'ping ' . microtime(TRUE);
         $service->send(new \PhpAmqpLib\Message\AMQPMessage($messageBody), Tx_Amqp_Messaging_Exchange::DEFAULT_EXCHANGE, $queue->getName());
         $receivedMessage = $service->receive($queue->getName());
         $admin->deleteQueue($queue->getName());
         if ($messageBody !== $receivedMessage->body) {
             return new tx_reports_reports_status_Status('AMQP', 'Warning', sprintf('Send and receive not identical. Message sent [%s] differs from received message [%s]', $messageBody, $receivedMessage->body), tx_reports_reports_status_Status::WARNING);
         }
         return new tx_reports_reports_status_Status('AMQP', 'OK', 'Connection successful. Send and receive OK.', tx_reports_reports_status_Status::OK);
     } catch (\Exception $e) {
         $statusMessage = $e->getMessage() . ' (' . get_class($e) . ')';
         return new tx_reports_reports_status_Status('AMQP', 'Error', 'Unable to send and receive messages. Reason: ' . $statusMessage, tx_reports_reports_status_Status::ERROR);
     }
 }