/**
  * @param Delivery $message
  *
  * @return Response
  *
  * @throws ReplyException
  */
 protected function createResponse(Delivery $message)
 {
     $headers = $message->getHeaders();
     if (!empty($headers['x-error'])) {
         throw new ReplyException($headers['x-error'], isset($headers['x-error-code']) ? $headers['x-error-code'] : 0);
     }
     $value = $this->getEncoder()->decode(new Encoded($message->getProperty('content-type', null), $message->getBody()));
     return new Response($value, $headers);
 }
Ejemplo n.º 2
0
 /**
  * @param Delivery $message
  *
  * @return Request
  *
  * @throws \Exception
  */
 private function createRequest(Delivery $message)
 {
     $topic = (string) $message->getRoutingKey();
     $headers = $message->getHeaders();
     $arguments = json_decode($message->getBody(), true);
     if (json_last_error() !== JSON_ERROR_NONE) {
         throw new EncodingException('Unable to decode request: ' . json_last_error_msg());
     }
     return new Request($topic, $arguments, $headers);
 }
Ejemplo n.º 3
0
 /**
  * Create and publish reply message for given request message.
  *
  * @param Delivery $request
  * @param string   $body
  */
 private function reply(Delivery $request, $body)
 {
     $reply = new Message($body, ['correlation-id' => $request->getProperty('correlation-id')]);
     $this->channel->publish($reply, '', $request->getProperty('reply-to'));
 }