Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function attach(MessageHandler $handler)
 {
     $this->server->on('request', function (Request $request, Response $response) use($handler) {
         $data = (object) array('message' => '');
         $request->on('data', function ($chunk) use($data) {
             $data->message .= $chunk;
         });
         $request->on('end', function () use($data, $handler, $response) {
             try {
                 $handler->receive($data->message);
                 $ack = new JobAcknowledgement();
                 $ack->setCreatedOn(new \DateTime());
             } catch (RuntimeException $e) {
                 $ack = new JobNotAcknowledgement();
                 $ack->setCreatedOn(new \DateTime());
                 $ack->setReason($e->getMessage());
             }
             $json = $ack->toJson();
             $response->writeHead(200, array('Content-type' => 'application/json; charset=utf-8', 'Content-length' => strlen($json)));
             $response->write($json);
             $response->end();
         });
         $request->on('error', function ($error) use($handler) {
             $handler->error($error);
         });
     });
 }
 /** @test */
 public function itShouldLogErrors()
 {
     $message = 'bloody exception';
     $exception = new \Exception($message);
     $logger = $this->getLogger();
     $logger->expects($this->once())->method('addError')->with($this->equalTo($message));
     $handler = new MessageHandler($this->getStompClient(), $logger);
     $handler->error($exception);
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function attach(MessageHandler $handler)
 {
     $pull = $this->pull;
     $this->pull->on('error', function ($error) use($handler) {
         $handler->error($error);
     });
     $this->pull->on('message', function ($message) use($pull, $handler) {
         try {
             $handler->receive($message);
             $ack = new JobAcknowledgement();
             $ack->setCreatedOn(new \DateTime());
         } catch (RuntimeException $e) {
             $ack = new JobNotAcknowledgement();
             $ack->setCreatedOn(new \DateTime());
             $ack->setReason($e->getMessage());
         }
         $pull->send($ack->toJson());
     });
 }