Пример #1
0
 /**
  * @param array $properties
  *
  * @throws MessageException
  */
 protected function checkRequiredPropertiesPresence(array $properties)
 {
     parent::checkRequiredPropertiesPresence($properties);
     if (MessageInterface::TYPE_RPC_RESPONSE != $properties[MessageInterface::PROPERTY_TYPE]) {
         throw MessageException::wrongMessageType($this->getType(), MessageInterface::TYPE_RPC_REQUEST);
     }
 }
 /**
  * @param AMQPMessage $amqpMessage
  *
  * @return BasicMessage|RpcRequestMessage|RpcResponseMessage
  * @throws MessageException
  */
 public function toMessageInterface($amqpMessage)
 {
     if (!$amqpMessage instanceof AMQPMessage) {
         throw MessageException::wrongMessageType(get_class($amqpMessage), 'AMQPMessage');
     }
     try {
         $msgType = $amqpMessage->get(MessageInterface::PROPERTY_TYPE);
     } catch (\Exception $e) {
         // Type is not defined in AMQPMessage properties => Load BasicMessage.
         $msgType = '';
     }
     // Instance proper message type
     switch ($msgType) {
         case MessageInterface::TYPE_RPC_RESPONSE:
             $message = new RpcResponseMessage($amqpMessage->body, $amqpMessage->get_properties());
             break;
         case MessageInterface::TYPE_RPC_REQUEST:
             $message = new RpcRequestMessage($amqpMessage->body, $amqpMessage->get_properties());
             break;
         case MessageInterface::TYPE_BASIC:
         default:
             $message = new BasicMessage($amqpMessage->body, $amqpMessage->get_properties());
             break;
     }
     // Set the original message
     $message->setOriginalMessage($amqpMessage);
     return $message;
 }
Пример #3
0
 /**
  * @param array $properties
  *
  * @throws MessageException
  */
 protected function checkRequiredPropertiesPresence(array $properties)
 {
     foreach ($this->getRequiredProperties() as $requiredProperty) {
         if (!array_key_exists($requiredProperty, $properties)) {
             throw MessageException::requiredPropertyMissing($requiredProperty);
         }
     }
 }
Пример #4
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);
     }
 }