/**
  * @expectedException \Retrinko\CottonTail\Exceptions\PayloadException
  */
 public function test_setResponse_withInvalidParams_throwsPayloadException()
 {
     $payload = RpcResponsePayload::create();
     $payload->setResponse(new \ArrayObject());
 }
Esempio n. 2
0
 /**
  * @throws RemoteProcedureException
  */
 protected function callback()
 {
     $procedure = $this->currentRequest->getPayload()->getProcedure();
     $params = $this->currentRequest->getPayload()->getParams();
     if (!is_callable([self::$proceduresClass, $procedure])) {
         throw RemoteProcedureException::procedureNotFound($procedure);
     }
     try {
         $executionResult = call_user_func_array([self::$proceduresClass, $procedure], $params);
         $payload = RpcResponsePayload::create($executionResult);
         $this->currentResponse->setPayload($payload);
     } catch (\Exception $e) {
         throw RpcExecutionException::executionError($e->getMessage());
     }
 }
Esempio n. 3
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);
     }
 }