コード例 #1
0
 /**
  * @inheritdoc
  */
 protected function publishToExchange(Message $message, \AMQPExchange $exchange)
 {
     // Create a response queue
     $queue = $this->declareResponseQueue($exchange);
     try {
         $attributes = (array) $message->getAttributes();
         // Setup correlation id
         $correlationId = isset($attributes['correlation_id']) ? $attributes['correlation_id'] : uniqid();
         // Patch attributes
         $attributes['reply_to'] = $queue->getName();
         $attributes['correlation_id'] = $correlationId;
         // Publish the message
         $isPublished = $exchange->publish($message->getMessage(), $message->getRoutingKey(), $message->getFlags(), $attributes);
         if (!$isPublished) {
             throw FailedToPublishException::fromMessage($message);
         }
         // Get the response
         $response = $this->waitForResponse($queue, $correlationId);
         if (!$response instanceof \AMQPEnvelope) {
             throw NoResponseException::forMessage($message);
         }
         return $response;
     } finally {
         // Cleanup
         $this->cleanupResponseQueue($queue);
     }
 }
コード例 #2
0
 /**
  * Publish the message to AMQP exchange
  *
  * @param Message $message
  * @param \AMQPExchange $exchange
  * @return bool
  * @throws \AMQPException
  */
 protected function publishToExchange(Message $message, \AMQPExchange $exchange)
 {
     $isPublished = $exchange->publish($message->getMessage(), $message->getRoutingKey(), $message->getFlags(), $message->getAttributes());
     if (!$isPublished) {
         throw FailedToPublishException::fromMessage($message);
     }
     return $isPublished;
 }
コード例 #3
0
 protected function publishToExchange(Message $message, \AMQPExchange $exchange)
 {
     $attributes = (array) $message->getAttributes();
     $attributes['correlation_id'] = $this->correlationId;
     $isPublished = $exchange->publish($message->getMessage(), $this->routingKey, $message->getFlags(), $attributes);
     if (!$isPublished) {
         throw FailedToPublishException::fromMessage($message);
     }
     return $isPublished;
 }