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;
 }
 /**
  * @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);
     }
 }
 /**
  * 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;
 }
 /**
  * @param Message $message
  * @param bool $return
  * @return Mockery\MockInterface
  */
 private function mockExchangeWithPublish(Message $message, $return = true)
 {
     $exchange = Mockery::mock(\AMQPExchange::class);
     $exchange->shouldReceive('publish')->once()->with($message->getMessage(), $message->getRoutingKey(), $message->getFlags(), $message->getAttributes())->andReturn($return);
     return $exchange;
 }