public function test_getPayload_returnsPayloadInterface()
 {
     $correlationId = uniqid();
     $contentType = MessageInterface::CONTENT_TYPE_PLAIN_TEXT;
     $properties = [MessageInterface::PROPERTY_CORRELATION_ID => $correlationId, MessageInterface::PROPERTY_CONTENT_TYPE => $contentType];
     $message = new RpcResponseMessage('', $properties);
     $payload = $message->getPayload();
     $this->assertTrue($payload instanceof PayloadInterface);
 }
예제 #2
0
 /**
  * @param RpcResponseMessage $response
  *
  * @throws MessageException
  */
 protected function onResponse(RpcResponseMessage $response)
 {
     $this->logger->notice('Message received!', ['body' => $response->getBody(), 'properties' => $response->getProperties()]);
     try {
         $this->rpcResponse = $response;
         if ($this->correlarionId != $this->rpcResponse->getCorrelationId()) {
             throw MessageException::wrongCorrelationId($this->rpcResponse->getCorrelationId(), $this->correlarionId);
         }
         // Send ack
         $this->connector->basicAck($response);
     } catch (\Exception $e) {
         // Create an error response and reject message
         $responsePayload = RpcResponsePayload::create()->addError($e->getMessage());
         $this->rpcResponse = MessagesBuilder::emptyRpcResponse($this->getSerializer()->getSerializedContentType(), $this->correlarionId);
         $this->rpcResponse->setPayload($responsePayload);
         $this->connector->basicReject($response, false);
     }
 }
예제 #3
0
 /**
  * @param RpcResponseMessage $response
  *
  * @return void
  */
 protected function sendResponse(RpcResponseMessage $response)
 {
     if ($this->currentRequest instanceof RpcRequestMessage) {
         $correlationId = $this->currentRequest->getCorrelationId();
         $response->setCorrelationId($correlationId);
         // Publish reponse message
         $this->connector->basicPublish($response, '', $this->currentRequest->getReplyTo());
     } else {
         $this->logger->warning('Imposible to send response! Invalid request.');
     }
 }