コード例 #1
0
ファイル: HTTPListener.php プロジェクト: gloubster/server
 /**
  * {@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);
         });
     });
 }
コード例 #2
0
 /** @test */
 public function itShouldWork()
 {
     $job = ImageJob::create('/path/to/source', new DeliveryMock(), array('format' => 'jpeg'));
     $logger = $this->getLogger();
     $logger->expects($this->never())->method('addError');
     $logger->expects($this->never())->method('addInfo');
     $client = $this->getStompClient();
     $client->expects($this->once())->method('isConnected')->will($this->returnValue(true));
     $handler = new MessageHandler($client, $logger);
     $handler->receive($job->toJson());
 }
コード例 #3
0
ファイル: ZMQListener.php プロジェクト: gloubster/server
 /**
  * {@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());
     });
 }