Esempio n. 1
0
 public function handle($id)
 {
     $this->id = $id;
     printf("Will connect on %s\n", $this->ip);
     $this->dealer->connect($this->ip, sprintf('dealer-%s', $this->id));
     $this->dealer->filter(function (Event $event) {
         return $event->is("/response/foo");
     })->subscribeCallback([$this, 'onFooResponse']);
     $this->dealer->filter(function (Event $event) {
         return $event->is("/response/bar");
     })->subscribeCallback([$this, 'onBarResponse']);
     echo "Will ask router every 5 seconds\n";
     $this->loop->addPeriodicTimer(5, [$this, 'askRouter']);
 }
Esempio n. 2
0
 public function handle()
 {
     printf("Will connect on %s\n", $this->sock);
     $this->pusher->connect($this->sock);
     echo "Will push keepalive every 5 seconds\n";
     $this->loop->addPeriodicTimer(5, [$this, 'keepAlive']);
     $this->httpd->route('POST', '/{type}', function (HttpdRequest $request, HttpdResponse $response) {
         try {
             $data = $request->getJson();
         } catch (\Exception $e) {
             $response->sendError($e->getMessage());
             return;
         }
         $type = $request->getRouteParam('type');
         $name = sprintf("/request/%s", $type);
         printf("Sending %s with data : %s\n", $name, json_encode($data));
         $this->pusher->send(new \Rxnet\Event\Event($name, $data));
         $response->text("It worked\n");
     });
     printf("You can send to puller from curl -XPOST http://127.0.0.1:23002/whatever -d'{'json':'encoded'}'\n");
     $this->httpd->listen(23002);
 }