Exemplo n.º 1
0
 /**
  * Handle internal service according to 8/MMI specification
  *
  * @param    string                 $frame  The frame
  * @param    \Scalr\System\Zmq\Zmsg $msg    The message
  */
 protected function handleInternalService($frame, $msg)
 {
     if ($frame == "mmi.service") {
         $name = $msg->getLast();
         $service = isset($this->services[$name]) ? $this->services[$name] : null;
         $code = !empty($service->workers) ? "200" : "404";
     } else {
         $code = "501";
     }
     $client = $msg->unwrap();
     $msg->setLast($code);
     //NOTE! We changed a bit ZMQ MDP protocol here.
     //The number of registered workers for the service follows the status frame.
     $msg->append(sprintf("%s", isset($service->workers) ? intval($service->workers) : "0"));
     $msg->push($frame);
     $msg->push(Mdp::CLIENT);
     $msg->wrap($client, "");
     if ($this->verbose) {
         $this->log("ZMQDEBUG", "responding mmi.service:\n--\n%s", (string) $msg);
     }
     $msg->setSocket($this->socket)->send();
 }