Esempio n. 1
0
 public function askRouter()
 {
     $what = mt_rand(0, 100) % 2 == 0 ? "foo" : "bar";
     $id = sprintf('%s-%s', time(), $this->id);
     printf("Send /%s request with id %s\n", $what, $id);
     $this->dealer->send(new Event(sprintf("/request/%s", $what), ['id' => $id]));
 }
 public function onNext($value)
 {
     if ($this->event) {
         $this->event->data = $value;
         $event = $this->event;
     } else {
         $event = new Event("/response", $value);
     }
     $this->zmq->send($event);
 }
Esempio n. 3
0
 public function handle()
 {
     printf("Will bind on %s\n", $this->sock);
     $this->puller->bind($this->sock);
     $this->puller->filter(function (Event $event) {
         return $event->is("/keepalive");
     })->subscribeCallback([$this, 'handleKeepAlive']);
     $this->puller->filter(function (Event $event) {
         return $event->hasPrefix("/request");
     })->subscribeCallback([$this, 'handleRequest']);
 }
Esempio n. 4
0
 public function keepAlive()
 {
     echo "Sending /keepalive\n";
     $this->pusher->send('/keepalive');
 }
Esempio n. 5
0
 public function handleBar(Event $event)
 {
     $slotId = $event->getLabel('address');
     printf("[%s]id %s, response sent\n", date('H:i:s'), $event->getData('id'));
     $this->router->send(new Event('/response/bar', ['id' => $event->getData('id')]), $slotId);
 }