public function test_constructor_withProperParams_populateBodyAndPropertiesProperly()
 {
     $correlationId = uniqid();
     $contentType = MessageInterface::CONTENT_TYPE_PLAIN_TEXT;
     $properties = [MessageInterface::PROPERTY_CORRELATION_ID => $correlationId, MessageInterface::PROPERTY_CONTENT_TYPE => $contentType];
     $message = new RpcResponseMessage('', $properties);
     // timestamp
     $this->assertFalse(empty($message->getTimestamp()), 'Empty timestamp!');
     $this->assertTrue(is_int($message->getTimestamp()), 'Timestamp is not int!');
     // type
     $this->assertFalse(empty($message->getType()), 'Empty type!');
     $this->assertEquals(MessageInterface::TYPE_RPC_RESPONSE, $message->getType(), sprintf('Type is not "%s"!', MessageInterface::TYPE_RPC_RESPONSE));
     // correlation id
     $this->assertFalse(empty($message->getCorrelationId()), 'Empty correlation id!');
     $this->assertEquals($correlationId, $message->getCorrelationId());
     // content type
     $this->assertFalse(empty($message->getContentType()), 'Empty content type!');
     $this->assertEquals(MessageInterface::CONTENT_TYPE_PLAIN_TEXT, $message->getContentType(), sprintf('Content type is not "%s"', $contentType));
     // body
     $this->assertTrue(empty($message->getBody()), 'Body is not empty!');
 }
Beispiel #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);
     }
 }