/**
  * @expectedException \Simples\ProcessManager\Exception\MessageTransformerException
  */
 public function testTrowExceptionIfCallInvalidMethodForRequest()
 {
     $request = new Request(function () {
     });
     $serializer = new Serializer();
     $transformer = new MessageTransformer($serializer);
     $encoded = $transformer->encodeRequest($request);
     $transformer->decodeResponse($encoded);
 }
Пример #2
0
 /**
  * Start manager loop
  */
 private function startLoop()
 {
     $this->client = $this->stompFactory->createClient();
     $this->client->connect()->then(function (Client $client) {
         $this->loop->addPeriodicTimer(self::PROVISION_TIME, function () {
             $this->provision();
         });
         $client->subscribe($this->channel, function (Frame $frame) use($client) {
             try {
                 $request = $this->messageTransformer->decodeRequest($frame->body);
                 $closure = $request->getClosure();
                 if (!is_callable($closure)) {
                     throw new ManagerException('Запрос не содерджит callable');
                 }
                 $result = $closure($this);
                 $response = new Response($result);
             } catch (\Exception $e) {
                 $this->logger->error('Exception при обработке запроса ' . $e->getMessage());
                 $response = new Response($e->getMessage(), Response::STATUS_ERROR);
             }
             if ($replayTo = $frame->getHeader('reply-to')) {
                 $body = $this->messageTransformer->encodeResponse($response);
                 $client->send($replayTo, $body);
             }
         });
     }, function (\Exception $e) {
         $this->logger->critical($e->getMessage());
     });
     $this->loop->run();
 }