예제 #1
0
function setupLogger()
{
    \SyRPC\Common::$lg = \SyRPC\Common::setupLogger('syrpc-php-test', Logger::DEBUG);
}
예제 #2
0
 /**
  * Tries to get the result for given result ID from RabbitMQ.
  *
  * @throws        AMQPTimeoutException
  * @param         string $resultId The UUID of the result to getc
  * @param         int    $timeout  Timeout in seconds after which the fetching shall stop
  * @returns       string           JSON encoded data string
  */
 public function getResult($resultId, $timeout = null)
 {
     if (is_null($timeout)) {
         $timeout = $this->timeout;
     }
     $hashId = Common::getHash($resultId, $this->amqNumQueues);
     $resultQueue = $this->getResultQueue($hashId);
     $this->waitId = $resultId;
     Common::$lg->addDebug(sprintf("Client waiting for request %s during %ds on %s (exchange %s)", $resultId, $timeout, $resultQueue, $this->resultExchange));
     $this->resultChannel->basic_consume($resultQueue, '', false, false, false, false, array($this, 'onResult'));
     while (!$this->response) {
         try {
             $this->resultChannel->wait(null, false, $timeout);
         } catch (AMQPTimeoutException $e) {
             Common::$lg->addCritical("Client hit the fan after {$timeout}s");
             throw $e;
         }
     }
     $res = json_decode($this->response);
     $data = $res->{'data'};
     $this->response = null;
     return $data;
 }
예제 #3
0
 /**
  * Callback function for when a request arrives on the request queue.
  *
  * @param         AMQPMessage    $msg  The message which arrived
  * @returns       void
  */
 public function onRequest($msg)
 {
     Common::$lg->addDebug("Server received a msg: " . print_r($msg->body, true));
     $body = Common::splitMessageBody($msg->body);
     if ($body) {
         $resp = json_decode($body);
         $resultId = $resp->{'result_id'};
         Common::$lg->addDebug(sprintf("Server received request %s (%s)", $resultId, $msg->get('delivery_tag')));
         $this->response = $body;
         $this->requestChannel->basic_ack($msg->get('delivery_tag'));
     }
 }